How to spellcheck a file via SSH using Vim

Through SSH you can check the spelling of a file or a document, for example, with the text editor Vim. First you need to open the file with Vim. To do this navigate to the folder containing the document that you want to spellcheck and type vim followed by the name of the file. For example:

vim example.txt

will open the file example.txt that's in the current working directory. Make sure you're in the normal mode of Vim by pressing the Esc button on your keyboard. Then type:

:set spell spelllang=en_us

and press Enter on your keyboard. In this case the spelling is checked according to American English. You can change that by modifying the last part of the command (e.g. :set spell spelllang=en_gb for British English). When you do it the text will be checked and the misspelled words will be highlighted in red. You can move the cursor to the next misspelled word by pressing ]s on your keyboard to go to the next misspelled word, and [s to go back to the previous misspelled word. When the cursor is on an incorrect word type z= and a list of suggested corrections will appear. Each word in the list has a number in front of it. If you see the correct word there, just type the number and press Enter. If it's not there, don't type any numbers and only press Enter to exit the list.

In case you didn't find the appropriate correction in the list, you can correct the word yourself. To do this, while you're still in Vim press the button i on your keyboard to enter the Insert mode. Then use the arrow keys on your keyboard to move the cursor, and correct the word by typing the necessary letters or by deleting letters using the backspace or delete button on your keyboard. After that press Esc to return to the normal mode of Vim.

To save the changes you've made to the file, while in the normal mode type :w and press Enter.

To learn all the basic functions of Vim you can use the Vim tutorial that you can access directly via SSH. To learn how to access it read the article on using the Vim tutorial via SSH. With this tutorial you can actually test everything yourself while you're reading it.

Was this answer helpful?

 Print this Article

Also Read