Vim crash tutorial

Vim has three modes, normal, insert and visual.

Normal

This is the default mode of Vim. In this mode, you can view the content and limited edits. Pressing esc under any other mode will bring you back to this mode.

  • r replaces the character the cursor is at. It can replace a character to one or multiple characters.
  • % goes to the matching parenthesis {}[]().
  • 0(zero) beginning of the line
  • $ end of the line
  • gg beginning of the file
  • G end of the file. Number+G jumps to specific line.
  • . repeats the previous command.

Search

  • f finds and moves to the next/nth occurence of a character. E.g., fq, 3fq.
  • * finds the next occurence of the word under cursor
  • # finds the previous occurence of the word
  • press ‘/’, then enter the string you want to search, hits enter. n/N goes to the next/previous occurence of the string.

Delete

  • x deletes the character the cursor is at in command mode.
  • d deletes the word. It can combine with movement keys and number. E.g., d2w removes 2 words.

Insert

A, a means append. O, o means new line.

  • i enters the insert mode without changing the position of the cursor.
  • a moves the cursor one character after and enters the insert mode.
  • o/O creates a new line after/before the current one and enters the insert mode at the new line .
  • I takes you to the beginning of the line in insert mode.
  • A takes you to the end of the line.

cc / C cleans the current line and is ready to change.

Multiple insert:

(the number of frequency)i(strings to be repeated) esc

E.g. 30i- esc

Visual

Selected text will be highlighted. Press v to enter this mode.


Navigation

This applies to all modes.

hjkl are the four keys to control the place of cursor. h and l control moving left and right. j moves downward while k moves upward.

Move by words:

  • w forward by a word, jump to the beginning(punctuation considered words)
  • W forward by a word, jump to the beginning (spaces separate words)
  • e moves to the end of this word(punctuation considered words)
  • E moves to the end of this word (spaces separate words)
  • b backward by a word, beginning

Movement keys can be combined with numbers. For example, 3l is moving right, 3 steps.

Exit

  • :w save
  • :q quit
  • :wq save and quit

Recommended resources

https://www.openvim.com/

https://vim.rtorr.com/

Leave a comment