38

How To Use Spell Check Feature In Vim Text Editor - OSTechNix

 5 years ago
source link: https://www.ostechnix.com/use-spell-check-feature-vim-text-editor/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How To Use Spell Check Feature In Vim Text Editor

by sk

· Published November 1, 2017 · Updated December 2, 2019

Vim is one of the best, most popular, feature-rich and powerful text editor. There is no doubt about that. It has lot of features. For example, the beginners can easily learn the basics of Vim from the built-in help-section by running “vimtutor” command in Terminal. Learning Vim is worth the effort. Today, in this guide, we will be discussing one of the most-widely used feature called “spell check” in Vim editor. If you’re a programmer who edits lots of text, then “spell check” feature might be quite useful. It helps you to avoid embarrassing spelling mistakes/typos while editing text files using Vim.

Use Spell Check Feature In Vim Text Editor

Enable Spell Check

To enable Spell Check feature in Vim, open it and type the following from Command Mode:

:set spell
Spell-Check-1-1.png

Enable Spell Check feature in Vim

Remember you need to type the above command inside Vim session, not in the Terminal window.

Find and correct spelling mistakes, typos

Now, go to “Insert Mode” (type “i” to switch to Insert Mode from Command mode) and type any misspelled letters. Vim will instantly highlight the misspelled words.

Spell-Check-2-1.png

As you see in the above output, I have typed “Welcome to Linux learng sesion” instead of “Welcome to Linux learning session” and vim is highlighting the misspelled words “learng” and “sesion” in red color.

Now, go back to Command mode by simply pressing the ESC key.

You can navigate through the misspelled words by typing any one of the following letters:

  • ]s – Find the misspelled word after the cursor (Forward search).
  • [s – Find the misspelled word before the cursor (Backward search).
  • ]S (Note the capital “S”) – Similar to “]s” but only stop at bad words, not at rare words or words for another region.
  • [S – Similar to “[s” but search backwards.

After you located the misspelled word, type z= to find suggestions for the that particular word. Here, Vim shows me the list of suggestions for the misspelled word “learng”. Pick the correct word from the list by typing the respective number and press ENTER key to update the misspelled word with right one.

Spell-Check-3.png

As you see in the above screenshot, I entered number 13 to replace the misspelled word “learng” with correct word “learning. Vim immediately updated the correct word in the input after I hit ENTER key.

Spell-Check-4.png

Similarly, correct all spelling mistakes in your text as described above. Once you’ve corrected all mistakes type :wq to save the changes and quit Vim editor.

Please remember – we can only check the spelling mistakes, not the grammar mistakes.

Set Spell language

By default, Vim uses “en” (all regions of English) to check for spelling mistakes. We can also choose our own spell language. For instance, to set US region English, type the following from the Command mode in Vim editor:

:set spell spelllang=en_us

The list of all available regions for the English language is:

  • en – all regions
  • en_au – Australia
  • en_ca – Canada
  • en_gb – Great Britain
  • en_nz – New Zealand
  • en_us – USA

Add words to Spellfile

Some times you might want to add some words as exceptions, for example your name, a command, Email etc. In such cases, you can add those specific words to the Spellefile. This file contains all exceptions.

Make sure you have ~/.vim/spell/ directory in your system. If it is not, create one:

$ mkdir -p ~/.vim/spell/

Then, set spellfile using:

:set spellfile=~/.vim/spell/en.utf-8.add

Now, locate the misspelled word using either [s or ]s and type zg. It will add the word under the cursor as good word in spellfile. i.e adds the words to your own dictionary.

Spell-Check-7.png

To undo this add (remove the word from spellfile), just use zug. To mark the mispelled word, type zw. To undo this action, use zuw.

Disable Spell Check in Vim

Vim will highlight all misspelled and words which are not available in the Dictionary. Some times, you find this annoying while writing code or a README file that contains a lot of words which are not available in the Dictionary. In such cases, you can disable the “Spell Check” feature by simply typing the following command:

:set nospell
Spell-Check-6.png

Disable Spell Check feature in Vim

That’s it. Now, Vim will highlight nothing. You can enable the spell check feature at any time by running “:set spell” from the Command mode in Vim.

Vim has more built-in help pages for Spell Check feature. To know more about spell check feature, run:

:help spell

You also refer individual help section for every options, for example:

:help ]s
:help [s
:help z=
:help zg
:help zug
:help zw
:help zuw
:help spelllang
:help spellfile
:help spellfile-cleanup

Also read:


And, that’s all for now. Hope this helps.

Thanks for stopping by!

Help us to help you:

Have a Good day!!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK