Just another geek's weblog

Monthly Archives: March 2007

Generally I spend all my day with a terminal and the vim opened. Besides writing code and stuff like that, you can use it for every kind of text that you want to write, not only code.

So, you’re now using firefox 2.x and you thought that the spell checking on every form was a nice idea? You can have spell checking automatically with any text that you edit with vim, and with any supported languages, nice hã?

So, here it’s some nice spell checking tips to use with your vim:

First, let’s open vim and put any text in there (I copied the vim description from wikipedia and added some errors):
Vim, which stands for Vi IMproved, is an opexn sourse,
multiplatform text editor extended from vi.
~
~
2,1 All

Now, let’s turn on the english spell checker (generally it comes with the default vim installation, on gentoo you can check if it’s installed verifying the app-vim/vim-spell-en ebuild).

:setlocal spell spelllang=en_us

After turning on the spell checker you’ll see that vim shows you where are the misspelling word:
Vim, which stands for Vi IMproved, is an opexnsourse,multiplatform text editor extended from vi.
~
~
2,1 All

Alright, this is cool, but how can I use vim to help me fixing these words? Now it’s time for vim magic 🙂

First, let’s show how to move on the misspelling words:

]s – Move to next misspelled word after the cursor.

[s – Like “]s” but search backwards, find the misspelled word before the cursor.

Now, how to ask vim spell checker for help:

z= – For the word under/after the cursor, vim suggest correclty spelled words. The results are sorted, in a list, on similarity to the word being replaced. To chose a word, just hit the word number and press <Enter>, or simply <Enter> to exit the suggested word list.

Cool, now you’re able to deal with the english spell checking in vim 🙂 . But I also speak brazilian portuguese, would be possible to get a portuguese spell file too? The answer is yes, we just need to download it from the the openoffice website (http://www.openoffice.org.br/verortografico) and tell vim to generate a portuguese spell file:
salveti@evalap /tmp $ wget http://www.deso-se.com.br/downloads/download.php?arquivo=pt_BR-2700g
salveti@evalap /tmp $ unzip pt_BR-2700g.zip
Archive: pt_BR-2700g.zip
inflating: pt_BR.aff
inflating: pt_BR.dic
inflating: Leia-me.pdf

Then, to build the vim spell file just open the vim editor and call the command :mkspell pt /tmp/pt_BR to create the file ~/.vim/spell/pt.<encoding>.spl . After building the file you can start using it with the command :setlocal spell spelllang=pt

Now, just one more tip, to help you dealing with different languages and spell checkers. Edit your .vimrc and put shortcuts for every one of then, like I did:
" English
:nmap <F5> :setlocal spell! spelllang=en<cr>
" Brazilian Portuguese
:nmap <F6> :setlocal spell! spelllang=pt<cr>

Now, when I’m using vim and want to check my words I just hit F5 for the English checking and F6 for Brazilian Portuguese. To turn it off just hit the same button again.