Published on

vim tutor

Authors

Vim provides a great tutorial tool called vim tutor. You can open it by using vim tutor or vimtutor.

By following the tutorial, you will get a basic idea how to use vim more efficiently in 20-30 minutes.

Basically, vim command has the grammar:

operator times motion

Here, operator means the operation you want to do: like delete, and times is an integer that represents how many times you want to repeat the operation. motion is the semantics you want the operation to do, like w, which represents a word, and e, end of a word.

So d5w means delete the following 5 words. If the operator is missing, it means moving by default. So 5w means moving the cursor by 5 words. There are 2 special motions: $, representing the end of the line and 0, representing the beginning of the line. Typing $ will take your cursor to the end of the line and d$ will delete from the cursor to the end of the line.

Due to the high frequency of deleting the whole line when editing in vim, deleting the whole line is simply dd. To delete multiple lines, use 5dd. You can use d5d, but that takes you longer time to type.

operater:

  • delete: d dw de
  • change: c ce
  • replace: r rx

Go to line: 78G, uppercase G

  • Search: /abc n for next N for previous
  • find matching parenthesis: %
  • visualize the block: v
    v, then move the cursor to highlight the selected text.

Next, execute: operator number motion.

vimrc config: with VI improved features.

vim ~/.vimrc
:r $VIMRUNTIME/vimrc_example.vim