Vim is very powerful tool. With it’s plugins, support for external programming languages and a vast community, you can do almost anything in it. But learning Vim is a slow process. Here I will try to put some knowledge that I would like to preserve for future use. Have a look, maybe you will find something useful.

Legend:

  • Control key will be marked as ^
  • Some special keys will be put in brackets, like <insert> key.

Basics

Quiting Vim

Well, that is more of a joke but what the hell.

To quit Vim go to command mode and press :q. If file was edited use :q! to quit without saving. Why not to save? I suspect that if anyone is looking for this tip, he or she doesn’t want to save changes just made to a file 😉

Spell checking

Vim can check your spelling. It can check word spelling but does not do grammar checks.

  • Turn on spell check: :set spell spelllang=en_us
  • Move cursor to next misspelled word: ]s, previous: ]s
  • Add word under cursor to local dictionary: zg. Note that it is added to a file specified as spellfile.
  • Showing suggestions for bad words: z=
    • To repeat replacement done by z= to all words in current window, use: :spellr[epall]
  • You can find more in VIM help: :help spell

Changing modes

There are 3 modes in VIM:

  • Command mode, that is a mode in which VIM normally starts. Captain obvious here – it is meant to issue commands. If you want to go back to this mode <Esc> key should help you.
  • Edit mode. You enter it by pressing <insert> key or by issuing some edit commands like i, I, a, A, etc.
  • Visual mode. Is used to select text. Take a look at Visual mode paragraph.

Visual mode

  • Start normal selection v
  • Start line selection: V
  • Start block selection: ^v
  • Reusing last selection: gv

Leave a Reply