Download and use of vim text editor in CentOs 7

1. Download the vim text editor

1. Enter the vim command in Linux, if it prompts command not found, it means that the vim editor has not been installed;

2. Enter the command [yum -y install vim] to download vim; 

3. Then enter the command [vim] to view the version information of vim. After viewing, enter the command [:q! ] to exit;

 2. Use of vim text editor

1. vim is an enhanced version of the vi editor, similar to the notepad used in the windows system. The vim editor has three modes:

  • Normal mode: This mode can also be said to be a normal browsing mode, which is equivalent to opening a text document in the window system and only browsing without doing anything;
  • Edit Mode: In this mode, you can edit and modify the content of the current text;
  • Command mode: In this mode, you can complete some operations on the text by entering some commands;

 2. Common commands and shortcut keys of vim editor:

  • Create a file: [vim file name], if the file already exists, enter the file directly;
  • Enter the editing mode and edit the content of the file: [Press i or o];
  • Exit the editing mode, return to the normal mode, and end the editing of the text: 【Press ESC】;
  • Enter command mode: [input: or /]
  • Exit command mode: 【Press ESC】
  • There are three ways to return to the Linux command line:

        1. Save the changes to the file and exit: [:wq]

Type: enter command mode, then type wq, then press enter

        2. Do not save the modification to the file: [:q]

Type: enter command mode, then type q, then enter

        3. Do not save the changes to the file, force quit: [:q!]

Type: enter command mode, then type q!, then press enter

  • Undo the editing content of the file, which is equivalent to crtl+z under windows: [u]

Make sure you are in normal mode first, then press u to undo

  • Copy the current line, then paste: [yy copy, p paste]

First make sure that it is in normal mode, move the cursor to the line to be copied, then press y twice, then move the cursor to the position to be pasted, and press p.

  • Copy multiple lines, then paste: [Number of lines + yy copy, p paste]

First ensure that it is in normal mode, move the cursor to the position of the first line to be copied, then press the number of lines to be copied, then press y twice, and then move the cursor to the position to be pasted, press p to Can

  • Delete the current line: [dd]

Make sure it is in normal mode, move the cursor to the line to be copied, and then press p twice to delete

  • Delete multiple lines: [Number of lines + dd]

First make sure that it is in normal mode, move the cursor to the line to be copied, then press the number of lines to be copied, and then press p twice to delete multiple lines

  • Find a keyword in the file: [/keyword]

Enter/enter command mode, then enter the keyword you want to find, press Enter, you can find it, and then enter n to view the next

  •  Display the line number of the file: [:set nu]; hide the line number of the file: [:set nonu]

Input: Enter command mode, then enter set nu and press enter to display the line number, then enter set nonu and press enter to hide the line number

  •  Move the cursor to the specified line number: [Enter the line number first, then press shift+g]

First make sure it is in normal mode, then enter the line number, and then press shift+g to move the cursor to the specified line number position

  •  Move the cursor to the first line of the file: [gg]; move to the last line: [shift+g]

First make sure that it is in normal mode, then press g twice to move the cursor to the first line; press shift+g to move to the last line

Guess you like

Origin blog.csdn.net/weixin_55118477/article/details/121050035