vi / vim command Detailed

1, create a file under Linux

vi test.txt or vim test.txt or touch test.txt

2, vi / vim use

Substantially vi / vim divided into three modes, namely, command mode (MODE the Command) , the input mode (Insert mode) , and the bottom line command mode (Last line mode).

(1) command mode

Copy the code
x, X x is a character backward delete, X is a previously deleted character 
NX (n represents a number) to delete characters backwards n 
dd deletes the current line 
D Delete all characters of the current line, a blank line again become the 
NDD (n represents a number) remove the cursor down the row n columns 
d1G cursor to delete all the data of the first row to the row 
dG delete all data cursor to the last row of 
yy copy cursor line 
y1G copy all the cursor line to the first line of data 
yG copy the cursor to the last row all data 
ynj (n represents a number) copying down cursor line n + 1 row 
dnj (n represents a number) to delete the cursor line down row n + 1 
p, P p is the data replication paste cursor on the next line, P to paste the copied data in the cursor line 
J bound cursor line data into line with the next line 
a recovery operation before u (Use the undo)
h cursor one character to the left 
j down cursor to a character 
cursor up one character k 
l cursor one character to the right 
Ctrl + f turn down a screen 
Ctrl + b upturned a screen 
Ctrl + d Down screen Total half-page 
Ctrl + u half-page screen upturned 
+ moves to the first non-blank character in the next line 
- the cursor to the first non-blank character in the current line 
n spaces (n represents a number) to the current cursor right line mobile n characters 
0 (number 0) move the cursor to the first character of the current line (can be null character, and attention - distinction) 
$ move the cursor to the last character of the current line (can be null character, attention and - distinguishing ) 
H cursor moves to the first non-blank character of the current line that the top of the screen 
first non-blank character M is moved to the current screen cursor that most middle row 
L cursor moves to the first non-blank character of the current line that the most of the bottom of the screen 
G of the cursor to the last line of the article in a first non-blank character 
first nG (n represents a number) Move the cursor to the n-th row of the article a non-blank character 
n cursor n first non-blank character lines down from the current row
Copy the code

(2) Input mode

i, I i is the current text input is inserted at the cursor, I is the line where the cursor is inserted into the first non-blank character input character 
a, A a is in the text at the current cursor insert a character input, A for the next character the cursor is located at the last character of the input text is inserted 
o, O o of the next line as the line of initial insertion cursor characters, O is the line where the cursor line on the first line starts inserting characters 
r , R r to replace a character that the cursor, R is a straight replacement text under the cursor until you exit the 
Esc to exit and return to command mode

(3) the bottom line of command mode

Copy the code
/ word lookup word string after the cursor 
word before the cursor lookup word string? 
: S / word1 / word2 / G find current cursor line word1, and replaced word2 
: n1, N2S / word1 / word2 / G at the n1 find between the rows and the second row n2 word1, and replaced word2 
:% S / word1 / word2 / G entire article to find word1, and replaced word2 
: W to save the edited data file to the hard disk 
: w [filename] edits after storage of the data file to another hard disk 
: r [filename] when editing data, the data is read into another file, put the contents of the file filename added cursor next line 
: wq or: x save and exit 
: q quit for unmodified files 
: q forced to quit without saving and exit apply to modify the file! 
: the SET NU display line numbers 
: set nonu cancel the line number 
: n1, n2 w [filename] to the n1 n2 line to save the contents of the file named filename
Copy the code

The following is the operation mode illustrating vi / vim of:

vi / vim FIG Keyboard:

source:

https://www.cnblogs.com/Jimc/p/10213914.html

Guess you like

Origin www.cnblogs.com/xiaoshen666/p/11118554.html