开发者

Is it possible to toggle a vim option when switching to insert mode?

开发者 https://www.devze.com 2023-02-12 08:38 出处:网络
I recently discovered the spell option thanks to this answer on Code Review, and I feel that the option is both really useful (while editing) and really annoying (while reading code, because of all th

I recently discovered the spell option thanks to this answer on Code Review, and I feel that the option is both really useful (while editing) and really annoying (while reading code, because of all the false positives).

I would like to somehow enable the option automatically when switching to insert mode:

set s开发者_开发知识库pell

and disable it automatically when switching back to normal mode:

set nospell


Adding the following commands in your .vimrc should do the trick (as long as your not using CTRL+C to leave insert mode) :

autocmd InsertEnter * setlocal spell
autocmd InsertLeave * setlocal nospell

Since this is a great trick, I have added these lines to my .vimrc !

if you want to get rid of words being highlighted, you can add them to the "good" word list by putting the cursor over them and type zg. See :help spellfor more information

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号