VIM’s common commands are worth having

Time:2021-6-21

The code writing in VIM mode is generally the exclusive skill of the great God level program ape, but it doesn’t mean that we don’t need to use VIM commands. When our program can only run in Linux environment, we have to learn some common VIM commands.

VIM has three common modes: general mode, edit mode and command mode.

Pattern

  • Up, down, left and right: kjhl can also use the direction key
  • N + up, down, left and right: n is a number, moving n characters up, down, left and right
  • [Ctrl] + F: the screen scrolls down one page
  • [Ctrl] + B: scroll the screen up one page, the same as page up
  • 0 or home: the cursor moves to the beginning of the line
  • $or end: the cursor moves to the end of the line
  • g: The cursor moves to the last line
  • Ng: move the cursor to the nth line
  • GG: same as 1g, the cursor moves to the beginning of the first line
  • /Word: find keywords down, use n or n to find keywords up or down
  • ? Word: look up the keyword word, use n or n to look up or down the keyword
  • : N1, N2S / word1 / word2 / G: S / 1 / 2 / g means to replace 1 with 2, so it means to replace word1 with word2 between N1 and N2. For example: 51100s / AAA / BBB / g
  • : 1, $s / word1 / word2 / G: full text search replace word1 with word2
  • x: Delete backward
  • 10: Delete forward
  • Nx: delete n characters backward
  • DD: delete current line
  • NDD: delete n rows down
  • D1g: delete the current position to the first line
  • D $: delete the current position to the last line
  • D0: delete all data from the current position to the first character of the new line
  • YY: copy the line where the cursor is
  • NYY: copy n rows down
  • p: Paste the copied data below the line where the cursor is
  • P: Paste the copied data above the line where the cursor is located
  • u: Redo previous operation
  • [Ctrl] + U: redo the previous operation

General mode to edit mode

  • i: Enter the insert mode, insert I in front of the cursor is inserted at the first non space character
  • a: Enter the insert mode, insert a character under the cursor is the last character in the line
  • o: Enter the insert mode, insert o in the lower line, and enter or exit in the upper line
  • r: Enter the replacement mode, similar to the insert key

Edit mode to general mode

  • ESC: exit edit mode and enter command mode

Command mode

  • : W save
  • :w! Forced preservation
  • : Q exit
  • :q! forced return
  • : WQ: X save and exit
  • ZZ save and exit
  • : set number displays the line number
  • : set nonu suppresses the display of line numbers

These commands are worth collecting!!!

VIM's common commands are worth having