≡ Menu

Vim Editor: How to Correct Spelling Mistakes Automatically

Vim Automatic Typo Correction
Photo courtesy of shandrew

This article is written by SathiyaMoorthy.

This article is part of the ongoing Vi / Vim Tips and Tricks Series. I tend to make simple spelling mistakes while writing, as English is not my first language. Wouldn’t be nice if Vim editor can do the spelling correction automatically as you make a typo?

Note: I wish someone from Nayv Navy football team read this article. Oh well, that would’ve still not fixed their problem.

In this article, let us review how to correct spelling mistakes automatically inside Vim editor.

There is a facility in VIM which can abbreviate/expand words for you. For example, when you type US, it can automatically be converted to United States. Add the following line to the ~/.vimrc to define the abbreviation.

$ vim ~/.vimrc
iab US United States

Once you’ve defined the above, anytime you type US inside Vim, it will be abbreviated to United States.

Vim can automatically correct your spelling mistakes while you are typing using one of the following methods.

  1. One method is to to teach Vim about the words that you typically make mistakes, and the correct spelling for it.
  2. Another method is to use a plugin that already has all the common spelling mistakes, and the correct spelling for it.

Method 1: Vim Spelling Correction – Using Custom Defined Words

Many advanced users might already be using the abbreviation technique for spelling correction. For example, add the following line to the ~/.vimrc. So when you wrongly type “teh”, it will be converted into “the” automatically.

$ vim ~/.vimrc
iab teh the

Whenever you find yourself making the same typo repeatedly, add it in to ~/.vimrc

$ vim ~/.vimrc
iab word_with_wrong_spelling correct_word

Method 2: Vim Spelling Correction – Using AutoCorrect.vim Plugin

The autocorrect.vim plugin has a collection of all typical spelling mistakes and it’s correct spelling.

Author of the Plugin, “Anthony Panozzo” describes about the plugin as: “Correct common typos and misspellings as you type”

Following are few examples from the autocorrect.vim plugin.

ia Britian Britain
ia Brittish British
ia Acceptence Acceptance
ia Acceptible Acceptable
ia accesories accessories

2 steps to Install the autocorrect.vim plugin

Step 1: Download the autocorrect.vim plugin

Download the plugin from vim.org website.

$ cd ~
$ wget -O autocorrect.tar http://www.vim.org/scripts/download_script.php?src_id=9900
$ tar xvf autocorrect.tar

Step 2: Install autocorrect.vim plugin

From Vim, you can execute “:source /path/to/the/autocorrect.vim” whenever needed (or) For permanent usage, add the following line to ~/.vimrc

$ vi ~/.vimrc
:source ~/autocorrect.vim

After doing this, when you make a typo of a word that is in the autocorrect.vim list, it will be corrected automatically.

$ vi test-typo.txt
thsi is acceptible

[Note: Above line will automatically change to "this is acceptable"]

When you want the expansion or spelling mistake correction to be stopped for a particular word, you can do the following inside vim. This is a temporary unabbreviation. If you want this to be permanent, remove the word either from ~/.vimrc or ~/autocorrect.vim.

$ vim test-typo.txt
:una US

Recommended Reading

Learning the Vi and Vim Editors, by Arnold Robbins. I’m a command-line junkie. So, naturally I’m a huge fan of Vi and Vim editors. Several years back, when I wrote lot of C code on Linux, I used to carry the Vi editor pocket reference with me all the times. Even if you’ve been using Vi and Vim Editors for several years and have not read this book, please do yourself a favor and read this book. You’ll be amazed with the capabilities of Vim editor.


This article is part of the ongoing Vi / Vim Tips and Tricks series. Please subscribe to TheGeekStuff and don’t miss any future Vi and Vim editor tips and tricks.

This article was written by SathiyaMoorthy, author of numbertotext Vim plugin, which will replace the numbers with the equivalent text inside Vim. The Geek Stuff welcomes your tips and guest articles.

Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Himanshu Sheth March 12, 2009, 11:58 am

    Very interesting, it would be very much useful; especially in Comments section.\

    Have digged and Delicious(ed) it.

    Liked your 101 Hacks as well.

    -Himanshu Sheth

  • David Engel March 12, 2009, 12:50 pm

    I use Vim for writing — diary, etc. — and coding, so one useful function I’ve found for autocorrect is from Anthony Panozzo (http://22ideastreet.com/blog/2008/11/06/vim-word-processing/).

  • frequser March 12, 2009, 10:25 pm

    Is it possible to do all these abbreviations, in windows? notepad or wordpad? kindly suggest.

  • Anthony Panozzo March 12, 2009, 10:27 pm

    Hi Sathiya,

    Just wanted to say thanks for including my plugin on your list of ways to correct with Vim! I really appreciated your emails in the past to talk about this before you posted. I thought that was very professional.

    If anyone has any corrections to the corrections they might want included in future versions of the plugin, feel free to email me at panozzaj@gmail.com or contribute to the github repository at http://github.com/tjweir/vim-autocorrect/tree/master. Thanks!

  • Narendra.s.v March 14, 2009, 4:56 am

    Wow!!! Nice and useful information. I have been using Vim editor for a long time and i didnt know this feature.Thanks for sharing this .

  • elwoode December 4, 2010, 5:13 am

    the autocorrect plugin only works for VIM ver 6.0 not the later 7 series

  • Anthony Panozzo December 5, 2010, 8:45 am

    @elwoode: I have only tested on the 7+ series, so it seems like this should be good. What problems are you having?

    On a different note, the github repo is now at https://github.com/panozzaj/vim-autocorrect.

    Hope this helps!

  • elwoode December 5, 2010, 2:01 pm

    got it working fine, not sure I will have it running by default though as it really slows the startup of Vim.

  • Anthony Panozzo December 5, 2010, 2:15 pm

    Yeah, I generally try to source it when needed like in the article. Once I had it autoload and was on a slower computer and it took awhile. Good idea!