Vi text editor common command function

Vi text editor common command function

When using the vi text editor, some shortcut commands will improve the efficiency of text editing, which are summarized as follows for easy reference.

For some practical advanced commands, please refer to vim advanced commands-block selection, multi-file editing, multi-window display, keyword completion commands

1. Description of buttons available in general command mode, cursor movement, copy and paste, search and replace, etc.
instruction Description
[Ctrl] + [f] Move one page down the screen, equivalent to the [Page Down] button
[Ctrl] + [b] Move the screen "up" by one page, equivalent to the [Page Up] button
0 or function key [Home] This is the number "0", move to the front character of this line
$ Or function key [End] Move to the last character in this line
G Move to the last column of this file
gg Move to the first column of this file
n <Enter> n is a number, the cursor moves down n columns
/word Look for a string named word under the cursor
:n1,n2s/word1/word2/g n1 and n2 are numbers, find the string word1 between lines n1 and n2, and replace the string with word2
:1,$s/word1/word2/g Find the word1 string from the first line to the last line, and replace the string with word2
:1,$s/word1/word2/gc Find the word1 string from the first line to the last line, and replace the string with word2, and display a prompt character before the replacement to confirm to the user whether to replace
x, X In a column of words, x is to delete one character backward (equivalent to [del] button), and X is to delete one character forward (equivalent to [backspace], which is the reverse key)
dd Delete the entire column where the cursor is
ndd n is a number, delete the downward n lines where the cursor is
yy Copy the column where the cursor is
nyy n is a number, copy down n lines where the cursor is
p, P p is to paste the copied data in the column under the cursor, and P is to paste in the column above the cursor
u Undo the previous action
[Ctrl]+r Redo the last action
. This is the decimal point, which means repeating the previous action
2. Description of the buttons available for switching from general command mode to edit mode
instruction Description
i,I Insert mode (Insert mode), i is'insert at the current cursor', I is'insert at the first non-blank character in the current column'
a,A Insert mode (Insert mode), a is'Insert at the next character where the cursor is currently located', A is'Insert from the last character in the column where the cursor is located'
o, O Insert mode (Insert mode), o is'insert a new column in the next column where the current cursor is located', O is'insert a new column in the previous column where the current cursor is located'
r,R Replace mode (Replace mode), r will only replace the character where the cursor is once, and R will always replace the text where the cursor is, until you press ESC
[Esc] Exit edit mode and return to normal command mode
3. Description of available buttons for switching from general command mode to command line mode
instruction Description
:w Write the edited data to the hard disk file
:q Exit vi
:wq Save and leave, if it is: wq! Then exit after forced save

Guess you like

Origin blog.csdn.net/qq_41019681/article/details/109954034