The previous article introduced the four modes of Vim. This article continues with the common commands of Vim, and it is highly recommended that you open a Vim to watch and practice. Last article address: juejin.cn/post/699133…

Create a new test file and start experimenting

  • touch test.txtCreate a new file
  • vim test.txtEnter vim’s normal mode
  • According to theiEnter insert mode and enter hello
  • According to theEscExit insert mode
  • According to theyyCopy the current row
  • According to thepPaste what you just copied

Now that you have a test file, you can use it to start practicing the common vim commands

The following instructions are in normal mode:

Common commands related to cursor movement

The entire document

  • gg: Moves to the first line of the document
  • 2gg: moves to the second line of the document
  • G: Moves to the last line of the document

A single

  • 0(Number 0) : Move to the beginning of the line
  • $: Moves to the end of the line

The word

  • b: Move to the beginning of a word
  • e: Move to the end of the word
  • 3w: Move to the beginning of the next third word

other

  • %: moves to the matching character, default is: (){}[]

Copy and paste the common delete commands

copy

  • yy: Copies the current row
  • 2yy: Copies the current two rows
  • yw(W: word) : copies a single word

paste

  • p: Pastes after the current cursor

delete

  • dd: Deletes the current row
  • 2dd: Deletes the current two lines
  • dw: Deletes a single word
  • x: Deletes a single character

Common undo and redo commands

undo

  • u: Undo the last operation

redo

  • ctrl+r: Redo the previous operation

Part of the commonly used commands are introduced, can be completed after learning through some operations to check, to the first newly created file as an example, perform the following operations to try:

  • Move to the beginning of the file
  • Move to the end of the current row
  • Copy the word
  • Move to the end of the file
  • Paste this word
  • Move to the beginning of the line
  • Delete current row

The above content can be made into a simple manual, more detailed commands can be seen at the following address

A more complete query website, for reference: vim.rtorr.com/