Sun Jan 10 08:02:11 PST 2021

Spell Checking in Vi (Vim)

I have been making more use of 'vi' to create documents containing written text recently. One problem with this is the lack of integrated spell checking in 'vi' - so I had a look for 'solutions' to this problem (or nice workarounds, at least). 'aspell' is straightforward to use - it does not do the highlighting that people have come to expect though. Checking around on this - I found that 'vi' has integrated spell check highlighting (nobody told me!).

Here is a simple .vimrc file that allows you to format a section of text '=', apply aspell to the entire file, switch on vi's spell checking, and turn on and off integrated 'vi' spell checking using the '+' and '-' keys (sometimes you do not want to have the highlighting of the spell check.

map = !}fmt -w 60 -d ''^M
map ^T :w!^M:!aspell check %^M:e! %^M
set spell
map + :setlocal spell^M
map - :setlocal nospell^M

Here the '^' symbol indicates a character sequence that begins with 'control-v' followed by the control character that you want to enter - e.g. 'enter' or 'control-t'. So ^T is entered as 'control-v control-t' and ^M as control-v enter'.

When you have these lines in your ~/.vimrc file, the following functions are enabled in vi.

'=' will run the 'fmt' program on the current paragraph and format this text at a width of 60 characters

'control-t' will run aspell on the current file. Aspell will take you through possible miss-spellings and allow you to correct them or accept corrected spellings.

'+' turns on interactive spell checking as is now built into vi.

'-' turns off interactive spell checking as is now built into vi.


Posted by ZFS | Permanent link | File under: linux, general, bash