[Linux] The use of vim, the Linux editing artifact

Table of contents

         1. The basic concept of Vim

         Two, the basic operation of Vim

                1. Enter vim

                2. Switch from normal mode to insert mode

                3. Switch from insert mode to normal mode

                4. Switch from normal mode to bottom row mode

                5. Exit the Vim editor

         3. Vim normal mode command set

                1. Move the cursor

                2. Delete text

                3. copy

                4. replace

                5. Revocation

         Four, Vim bottom line mode command set

                1. List the line numbers

                2. Cursor jump

                3. Find characters

                4. Replace characters

 


 

1. The basic concept of Vim

     Vim is a multi-mode editor. In fact, we only need to master these three, which are command mode, insert mode and last line mode.

       Command Mode (Normal Mode/Normal Mode)

Control the movement of the screen cursor, delete characters, words or lines, move and copy a section and enter the insert mode , or the bottom line mode .

       insert mode

Only in the insert mode, you can do text input, press the "ESC" key to return to the command mode . This mode is the most frequent editing mode we will use later.

       Bottom Row Mode 

Save or exit the file, you can also perform file replacement, find character strings, list line numbers and other operations. In command line mode, press shift+: to enter this mode. To view all your modes: open vim, enter directly in the bottom line mode: help vim-modes to view.

Two, the basic operation of Vim

   1. Enter vim

    Enter vim, enter vim and the file name at the system prompt, and then enter the vim full-screen editing screen: vim test.c, if there is a file of this test.c, it will be entered directly, if not, it will be automatically created and entered.

At this point, you have already entered the editor, but this is only in the normal mode and cannot be edited.

   2. Switch from normal mode to insert mode

    There are 3 ways to switch from normal mode to insert mode. You can directly enter insert mode by pressing a or i or o. At this time, the edit box below also changes, as shown in the figure below:

    The lower left corner becomes INSERT, indicating that the insert mode has been switched, and it can be edited at this time.

   3. Switch from insert mode to normal mode

    To switch from insert mode to normal mode, just press the Esc key to exit.

   4. Switch from normal mode to bottom row mode

    To switch from the normal mode to the bottom row mode, we need to press the Shift + : key combination to enter the bottom row mode. Note : it is not possible to directly enter the bottom row mode from the insert mode. You need to exit the insert mode first and enter the bottom row mode from the insert mode .

   5. Exit the Vim editor

    Exiting the Vim editor is exiting from the bottom line mode . When you see (:), enter the corresponding letter after the colon to exit.

q: Enter q to exit directly, and will not save the edited content just now.

wq: It is to save first, and then exit.

q! : It is a forced exit.

    We usually use wq to exit, otherwise the things we edit will not exist.

    Note: The above commands can only be executed in the case of English input , and the command will not be executed in the case of Chinese input.

3. Vim normal mode command set

   1. Move the cursor

  • Vim can directly use the cursor on the keyboard to move up, down, left, and right, but regular vim uses lowercase English letters "h", "j", "k", and "l" to control the cursor to move left, down, up, and right by one grid;
  • Press "G": Move to the end of the document;
  • Press "$": move to the "end of line" of the line where the cursor is located;
  • Press "^": move to the "beginning" of the line where the cursor is located;
  • Press "w": the cursor jumps to the beginning of the next word;
  • Press "e": the cursor jumps to the end of the next word;
  • Press "b": the cursor returns to the beginning of the previous word;
  • Press [gg]: go to the beginning of the document;
  • Press [shift+g]: enter the end of the document;
  • Press [n + shift + g]: position the cursor on the specified n line;
  • Press [shift+~]: Convert the letter where the cursor is located to upper and lower case;
  • Press "ctrl" + "b": the screen moves to the "back" by one page;
  • Press "ctrl" + "f": the screen moves "forward" by one page;
  • Press "ctrl" + "u": the screen moves half a page to the "back";
  • Press "ctrl" + "d": the screen moves half a page "forward".

   2. Delete text

  • Press "x": Each time you press, a character at the cursor position will be deleted;
  • Press "n + x": means to delete the 6 characters " behind (including yourself)" where the cursor is located ;
  • Press "X": uppercase X, every time you press it, delete a character "before" where the cursor is located;
  • Press "n + X": means to delete the " previous " 20 characters where the cursor is located ;
  • Press "dd": delete the line where the cursor is located;
  • Press "n + dd": delete n lines from the line where the cursor is located.

   3. Copy

  • Press "yy": copy the line where the cursor is located to the buffer;
  • Press "n + yy": it means to copy 6 lines of text "counting down" from the line where the cursor is located;
  • Press "p": Paste the characters in the buffer to the position of the cursor; Note: All copy commands related to "y" must cooperate with "p" to complete the copy and paste function.

   4. replace

  • Press "r": replace the character at the cursor position;
  • Press "R": replace the character where the cursor is, until the "ESC" key is pressed.

   5. Revocation

  • Press "u": If you execute a command by mistake, you can immediately press "u" to return to the previous operation. Multiple restores can be performed by pressing "u" multiple times.
  • "ctrl + r": undo redo.

Four, Vim bottom line mode command set

   1. List the line numbers

set nu : After entering the command, press the Enter key, and the line number will be displayed in front of each line of the code.

 At this point there are no line numbers.

This completes the addition of line numbers.

   2. Cursor jump

In the bottom line mode, input a number n, press Enter, and the cursor will come to the nth line.

 

   3. Find characters

 In bottom line mode, enter [? + the character you are looking for] .

   4. Replace characters

In the bottom line mode, enter [%s/xxx/xxx/g] to complete the replacement. For example, %s/hello/HELLO/g , the replacement is completed.

 

 


 

If there are deficiencies in this article, you are welcome to comment below, and I will correct it as soon as possible.

 

 Old irons, remember to like and pay attention!!! 

Guess you like

Origin blog.csdn.net/m0_63198468/article/details/128585687