DEV Community

Cover image for Activating the native spell-checking on Vim
Vinicius Brasil
Vinicius Brasil

Posted on

Activating the native spell-checking on Vim

Developers write not only code but documentation, bug reports, commit messages. As a non-native English speaker, I always find myself using Hemingway App, Grammarly, and other similar tools. They help but it is quite annoying having to switch back and forth from my editor to these tools.

The good news is that Vim ships with a spell-checker. It can check for words that do not exist, wrong capitalization, and even words that were spelled wrong for the selected region.

To turn the spell-checking on, you can use this command:

:setlocal spell spelllang=en_us
Enter fullscreen mode Exit fullscreen mode

You can also hook it to a specific file type, for example:

" this goes into your init.vim/.vimrc file
autocmd FileType gitcommit setlocal spell
Enter fullscreen mode Exit fullscreen mode

Happy Vimming!

Discussion (3)

Collapse
pbnj profile image
Peter Benjamin (he/they) • Edited

Tip:

If you want a quick way to toggle spell on/off (like in vim-unimpaired):

nnoremap <expr> yos &spell == '0' ? ':setlocal spell<cr>' : ':setlocal nospell<cr>'
Enter fullscreen mode Exit fullscreen mode

Now, you can type yos in Normal mode to toggle spell on/off.

Collapse
siddharthshyniben profile image
Siddharth

Another tip: Use z= to fix spelling

Collapse
pbnj profile image
Peter Benjamin (he/they)

And:

  • ]s to go to next misspelled word
  • [s to go to previous misspelled word
  • zg to mark a misspelled word as good
  • zw to mark a word as bad or wrong

Type :help spell in vim for more information.