Chapter 4 linux editor - the use of vim

1. What is vim?

v i m vim vi im is a multimodal code editor. There are three types of modes commonly used in vim: command mode, insert mode and last line mode. The main functions of these three modes are as follows:

  • Command mode: This mode is also called normal mode, common mode, etc. Its main function is to control the movement of the screen cursor, and control the deletion, movement, and copying of codes.
  • Insert mode: In this mode, the code writing work is carried out. Press and hold [Esc] to enter command mode from insert mode.
  • Bottom line mode: In this mode, we can save and exit files, and at the same time, we can also perform text replacement, search for character fragments, display line numbers, etc.

Two, the basic operation of vim

1. Mutual switching between modes

The switching between the above three common modes can be summarized as the following figure.
insert image description here

2. The common command set of vim

(1) Common commands in normal mode

a. Mode switching

  • [i]: Enter insert mode, and insert from the current position of the cursor.
  • [a]: Enter insert mode, and insert from the next position of the cursor position.
  • [o]: Enter insert mode, insert a new line, start input from the beginning of the line.
  • [shift]+[;]: Enter bottom row mode.

b. Cursor movement

  • [h], [j], [k], [l]: respectively control the cursor to move left, down, up, and right by one unit.
  • [G]: Move to the end of the article.
  • [gg]: Move to the beginning of the article.
  • [w]: The cursor jumps to the beginning of the next character.
  • [e]: The cursor jumps to the end of the current character.
  • [b]: The cursor returns to the beginning of the previous character.
  • [shift]+[4]: Move to the end of the current line.
  • [shift]+[6]: Move to the beginning of the current line.
  • [ctrl]+[b]: Move the screen back one page.
  • [ctrl]+[f]: Move the screen forward one page.
  • [ctrl]+[u]: Move half a page back on the screen.
  • [ctrl]+[d]: Move the screen half a page forward.
  • [ctrl]+[g]: List the line number of the line where the cursor is located.
  • [#G]: Move the cursor to the beginning of line #.

c. Delete text

  • [x]: Each time you press, delete a character at the cursor position.
  • [#x]: Delete the # characters after the cursor position (including the current position), for example [2x], delete the 2 characters after the current position.
  • [X]: uppercase X, delete a character before the cursor position.
  • [#X]: Delete the # characters in front of the cursor position (excluding the current position).
  • [dd]: Delete the line where the cursor is located.
  • [#dd]: Starting from the line where the cursor is located, delete the # line. For example: [2dd], delete 2 lines including the current line.

d. copy

  • [yw]: Copy the characters from the cursor position to the end of the word into the buffer.
  • [#yw]: Copy # characters to the buffer.
  • [yy]: Copy the line where the cursor is to the buffer.
  • [#yy]: Starting from the line where the cursor is located, copy the # line to the buffer.

e. replace

  • [r]: Replace the character where the cursor is located.
  • [R]: Replace the character where the cursor is, until the [Esc] key is pressed.

f. Revocation

  • [u]: Undo the previous operation, press [u] multiple times to achieve multiple undo.
  • [ctrl]+[r]: Redo the last undone operation.

g. change

  • [cw]: Change the word where the cursor is to the end of the word.
  • [c#w]: Change # characters.

(2) Common commands in bottom line mode

a. Display line number

Enter set nu in the bottom line mode.

b. Jump to a certain line of the file

In the bottom line mode, directly input a number #, and press Enter to jump to the #th line of the file.

c. Find characters

  • [/keyword]: first input a '/', and then input the keyword of the content we want to find, if the keyword we searched for the first time is not what we want, we can press [n] until we find what we want need. (search from top to bottom)
  • [?Keyword]: First input a '?', and then input the keyword of the content we want to find. If the keyword we searched for the first time is not what we want, we can press [n] until we find what we want need. (search from bottom to top)

d. File preservation and launch

  • [w]: Save the file.
  • [q]: Quit the file.
  • [wq]: Save and exit the file.

Guess you like

Origin blog.csdn.net/weixin_72060925/article/details/131213186