Spellchecker in VIM

Dawid Laszuk published on
3 min, 505 words

Only recently I've started using VIM as my default editor and... I'm amazed.

I'm not advocating here for its superiority over any other text editor. You might be into design or simply wish for a graphical interface. I'm into not-using-mouse too much, so it actually fits quite well my purposes. Having said that, it took me a while to discover it with more commands than saving and exiting.

One of the features that from the outsider point of view, i.e. myself a month ago, that it couldn't possibly ever have is spellchecker. Not that I actively thought that vim doesn't have a spellchecker, but rather that passively ignoring the idea of suggesting corrections in a terminal. I was wrong. Vim has spellchecker and it's pretty good.

The magical command is: :setlocal spell spelllang=XX where for English XX is one of {en, en_au, en_ca, en_gb, en_nz, en_us}. If you have a problem with setting up British, like I had, try command: :setlocal spell! spelllang=en_gb i.e. with extra exclamation mark.

Actually I suggest mapping command to some keyboard key, so when you press it turn on/off highlighting mode. To do this edit your .vimrc file (Ubuntu: ~/.vimrc) and add following line: :map :setlocal spell! spelllang=en_gb which means that whenever you press key F7 it will toggle command.

Once you have this set and someone introduces mistakes into your text/code, you can simply navigate between these using ]s and [s for next and previous, respectively. Obviously you can also just navigate using keys or hjkl, but who doesn't want to feel like hacker?

Assuming someone has played with your text and make it less perfect, you have two options:

    z=   acceptance of the mistake and listening for looking up some suggestions, or
    zw   teach your dictionary this new fabulous word, or
    zg   denial, blissful ignorance, snooze button.

If you change your mind with your last command you can undo it using zuw or zug. I suggest quick read about these commands in Quick Start from spell documentation or :help spell.

Now! The default setting for spellchecking performance are against large files/projects, like PhD thesis. If you notice that after certain line spellchecker doesn't inform you about the obvious mistake then you should use this StackOverflow advice and increase your syn sync parameters. In short, but I suggest reading the SO question and answers (and comments), you can increase minlines and maxlines in (Ubuntu) ~/.vim/after/syntax/tex.vim with: [code language="bash"]syn sync maxlines=20000 syn sync minlines=500 [/code]