Enable spellcheck and language in vim

vim_compMy favourite lightweight editor on Linux is Leafpad. Though I am more comfortable with vim, I use Leafpad for drafting articles like this one. An option Leafpad lacks is spell checking and I was looking for another alternative to do that. However, most of them were bulky or written in languages like Python making them damn slow.

Finally I ended up enabling spell check by default in vim. To do that, I added the following in ~/.vimrc:

set spell

However, I prefer to use UK English spellings. The system default is US English. To use the UK option I ad to add the following:

setlocal spell spelllang=en_gb

Note that this also enables spellcheck so you do not need to add the earlier switch. To urn it off, type in the following while in command mode of vim:

:set nospell

To check only comments and not actual code, add the following line:

syntax enable

The syntax description files already know what to check and what not.

To add a word to the dictionary, place the cursor on the word and press <zg> in command-mode.

Whitespace removal on save

To remove all trailing whitespace characters from a file when you save it, add the following auto-command to ~/.vimrc:

autocmd BufWritePre * :%s/\s\+$//e

To specify a single file type:

autocmd BufWritePre *.c :%s/\s\+$//e

To specify certain file types:

autocmd FileType c,cpp,java,php autocmd BufWritePre <buffer> :%s/\s\+$//e

Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s