Review the various uses of Vim text editor

I. Overview

There are three modes in the Vim editor: command mode, last line mode and edit mode. Each mode supports a variety of different command shortcut keys, which greatly improves work efficiency.

  1. Command mode: Control cursor movement, copy, paste, delete and search text.
  2. Input mode: normal text input.
  3. Last line mode: save or eject the document, and set the editing environment.

Switch between two different modes

Every time you run the Vim editor, it enters the command mode by default. At this time, you need to switch to the input mode before writing the document, and every time you finish writing the document, you need to return to the command mode and then enter the last line mode to execute Save or eject the document.

In Vim, it is not possible to switch directly from input mode to last line mode. There are hundreds of built-in commands in the Vim composing editor, in order to help readers master the Vim editor more quickly.

Common commands in three-command mode

command effect
dd Delete (cut) the entire line where the cursor is
5dd Delete (cut) 5 lines from the cursor
yy Copy the entire line where the cursor is
5yy Copy 5 lines from the cursor
n Display the next character string located by the search command
N Display the last character string located by the search command
u Undo the operation of the previous step
p Paste the previously deleted (dd) or copied (yy) data behind the cursor

Common commands in the four-line mode

The last line mode is mainly used to save and exit files, and to set the working environment of the Vim editor. It also allows users to execute external Linux commands or jump to a specific number of lines in the written document. We can easily switch from command mode to last line mode with a colon.

command effect
:w Save
:q drop out
:q! Force quit and discard the modified content of the document
:wq! Force save and exit
: set no Show line number
:set nonu Do not display line numbers
:command Execute the command
: Integer Jump to this line
:s/one/two Replace the first one in the line where the current cursor is with two
:s/one/two/g Replace all one in the line where the cursor is currently with two
:%s/one/two/g Replace all one in the full text with two
?String Search the string from bottom to top in the text
/String Search the string from top to bottom in the text

Five command mode to switch to input mode

The command to switch from command mode to input mode can be a, i, o:

  1. a key: Enter a character at a position behind the cursor.
  2. i key: Input characters at the current position of the cursor.
  3. o key: A blank line will be created under the cursor. At this time, press the a key to enter the input mode of the editor.

Supplement: We can view the contents of the file through the cat command.

Guess you like

Origin blog.csdn.net/calm_encode/article/details/113358853