---
title: Vim Spell-Checking
teaser:
tags: vim
author: Dan Croak
published_on: 2013-11-19
---

There are times when we edit prose in Vim, such as in a project `README` or git
commit message. In those cases, we can use Vim's spell-checking to help us
avoid embarrassing mistakes.

## Switching on spell-checking

We can switch on spell checking with this command:

    :setlocal spell

We can also specify the language:

    :setlocal spell spelllang=en_us

## What does it look like

Here's a screenshot of what I see as I edit this blog post:

![''](https://images.thoughtbot.com/vim-spell-check.png)

The highlighted words are considered misspellings.

## Spell check per filetype

It would be tedious to manually turn on spell-checking each time we need it.
Luckily, we can guess by convention that we'll want to spell-check certain files.

We automatically turn on spell-checking for Markdown files based on their file
extension with this line in our `~/.vimrc` via [thoughtbot/dotfiles][dotfiles]:

    autocmd BufRead,BufNewFile *.md setlocal spell

[dotfiles]: https://github.com/thoughtbot/dotfiles/blob/master/vimrc

Another way to do it for certain filetypes is like this:

    autocmd FileType gitcommit setlocal spell

## We get word completion for free

By turning on spell-checking in our `~/.vimrc`, we'll be turning on word
completion as well. The following command will let us press `CTRL-N` or
`CTRL-P` in insert-mode to complete the word we're typing!

    set complete+=kspell

## Add words to the dictionary

We can add words like "RSpec" or "thoughtbot" to the `spellfile` (just a list
of correctly-spelled words, not a list of magical incantations) by cursoring
over those words in a file and typing:

    zg

## What's next

If you found this useful, you might also enjoy:

* [:help spell][spell]
* [Wrap Text at 80 Characters in Vim][wrap]
* [Sort Lines Alphabetically in Vim][sort]
* [Tab Completion in Vim][tab]
* [No Newline at End of File][newline]

[spell]: http://vimdoc.sourceforge.net/htmldoc/spell.html
[wrap]: https://thoughtbot.com/blog/wrap-existing-text-at-80-characters-in-vim
[sort]: https://thoughtbot.com/blog/sort-lines-alphabetically-in-vim/
[tab]: https://thoughtbot.com/blog/vim-you-complete-me/
[newline]: https://thoughtbot.com/blog/no-newline-at-end-of-file/
