neovim / vim - spell correction (including syntax)
NeoVim and Vim are great terminal text editors. They are configurable and have many extensions that can make neovim and vim even better than an IDE. Vim comes inbuilt with a spell checker since v7. NeoVim is based on Vim and, as a result, has the same functionality. This article will discuss how you can use the inbuilt spell checker with your code.
Enable Spelling
The spell-check tool in Vim is spell
. To enable spell in US English, you can use the following Vim command.
:setlocal spell spelllang=en_us
If you would like this to be enabled globally, you can add the following to your neovim / vim configuration file. In a traditional vim configuration, this would be ~/.vimrc
. If you are in neovim, you can add it to ~/.config/nvim/init.vim
or in file sourced by the init.vim
file.
autocmd BufRead,BufNewFile * setlocal spell spelllang=en_us
For some reason, if you only want spell check to be performed in certain file types:
autocmd BufRead,BufNewFile *.md setlocal spell spelllang=en_us
Note: autocmd
is a vim command that allows you to automatically run a command when a file is opened and written to.
Check Code Spellings
The Vim spell checker by design doesn't check syntax spellings. There exists no configuration option to spell that can check syntax spelling. However, you can turn off syntax, and the spell checker will highlight all errors.
:set syntax=off
Once you have completed spell correction, you can turn it back on.
:set syntax=ruby
Usage
There are a variety of commands at your disposal. I recommend you use the plugin help for a full list of supported commands.
]s " Move to the next misspelt word
[s " Move to the previous misspelt word
z= " Provide suggestions (you can entire the suggestion ID and enter to replace the word)
zg " Add a word to the dictionary
Plugin Help
Spell documentation is extensive. You can access spell documentation from within Vim using the help command.
:help spell
Conclusion
NeoVim and Vim are great text editors used by tens of thousands of developers. Developers need all the help they can get as they find themselves in high-stress situations solving complex software issues. Using a spell checker doesn't mean one doesn't know to spell. As we type fast under duress, it's normal to make errors. This is why I recommend every developer under my preview use a spell checker. NeoVim and Vim make it easy by including an inbuilt capable spell checker with suggestions without the need for any third-party plugins. I hope this article helps you with your needs.
About the Author
Ziyan Junaideen -
Ziyan is an expert Ruby on Rails web developer with 8 years of experience specializing in SaaS applications. He spends his free time he writes blogs, drawing on his iPad, shoots photos.