Skip to main content
   
Andrew Roberts @ School of Computing

Spell-checking within Vim

Believe it or not, it is an advantage that Vim doesn't come with its own built-in spell checker. The reason being is that it gives you the choice to use the many other reliable checkers that have been developed.

I personally prefer Ispell. This is a mature system that is installed on many Linux systems (if not, it is simple to install.) It supports over 30 languages too, which means it is extremely flexible.

To get the spell checking functionality permanently within your Vim setup, you must edit your ~/.vimrc file. Vim checks this file whenever it is executed. Add the following to the end of the file:

map <F7> :w<CR>:!ispell -x -d british %<CR><CR>:e<CR><CR>

It may look a bit confusing, but these instructions tell Vim to basically run Ispell interactively whenever the user presses the F7 key. It has to save the file your currently working on before Ispell can get to work. It will then look through your file, and whenever it comes across a word it doesn't recognise, it offers you a list of likely alternatives, or the option to add/ignore etc.

Highlighting Spelling Errors

A lot of people have become accustomed to the red underlines within MS Word to indicate spelling errors as you type. If that is the way you like to work, there are plugins that you can download to add this functionality. The best I've seen so far is Ajit Thakkar's imaginatively named SpellChecker.vim. It can cope with spotting errors within a variety of programming languages too, including Latex.

It may also be worth checking out the Vim info at Stripey.com. It is from here where I found the information to add the spell-checker into Vim. There is another highlighting error spell-checker, although not as impressive, as it requires the user to manually press a button to check the file all at once, rather than checking as you are typing. But, it does cope with HTML files very well. There is also lots of other good tips on Vim here too.


< Back to Misc.