Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 spell

and disable it automatically when switching back to normal mode:

set nospell
like image 644
Eric Bréchemier Avatar asked Feb 18 '11 11:02

Eric Bréchemier


1 Answers

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

like image 105
Xavier T. Avatar answered Sep 16 '22 15:09

Xavier T.