This article is your own study notes, welcome reprint, but please specify the source: http://blog.csdn.net/jesson20121020
The most powerful text editor under Linux is Vi/vim, and its commands, if used flexibly, are more efficient than other text editors when writing programs or editing text.
Vi/vim There are no menus, only commands, there are three modes of operation: Command mode, insert mode, and edit mode, three relationships such as
VI Common Command Insertion command:
A after the cursor is inserted
A at the end of the bank additional text
I insert before the cursor
I Insert text on the bank first
o Insert a new line under the cursor
O insert a new line on the cursor
Locate command:
H, the left arrow moves one character
J, move down one character in the direction key
K, move the key up one character in the direction
L, right-click one character to the right
$ move to end of line
0 move to the beginning of the line
H Move to upper screen
M moves to the center of the screen
L move to the bottom of the screen
: Set NU Displays line number
: Set Nonu Cancel line number
GG to First line
G to last line
: $ to last line, same as G function
NG to Nth row
: N to Nth row
CTRL+F Scroll forward one page
CTRL+B Scroll Backward one page
Delete command:
x Delete the character of the cursor
NX removes the n characters after the cursor is located
DD deletes the cursor in the row
NDD Delete the following n rows of the row where the cursor is located
DG deletes the contents of the line to the end of the file cursor
D0 Delete all the contents of the cursor at the beginning of the bank
d$ Delete all content at the end of the line where the cursor is located
D Delete all the contents of the cursor at the end of the line, with d$
DW Delete a Word
NDW Delete the first n words where the cursor is located
: nd deletes the nth row
: n1,n2d Delete all contents of line N1 to N2
: N1,n2 mo $ moves the contents of the N1 line to the N2 row to the last row
Copy and cut
yy, Y copy when forward
Nyy, NY Copy the following n rows of the current row
DD cuts the current line, which is actually delete
NDD cuts the current row following n rows
: N1,N2 Co n3 copies all the contents of the N1-N2 line to line N3
: N1,N2 co $ will get all the contents of the N1-N2 line to the last line
Paste command
P Paste to the next line in the current row
P paste to the previous row of the current line
Cancel command
U Cancel the previous action
Search and replace
/string search for the location of the string, n from the back to find, n from the back, search, if you want to ignore the case, then add: Set IC
:%s/old/new/g full text Replace specified string
: S/old/new replaces the first specified string that appears on the current line
: s/old/replaces all specified strings of the current line
: N1,N2 s/old/new/g replaces the specified string in a n1-n2 row
Save and exit
: Wq Save Exit
: wq! Force Save exit
: X and: Wq functions like
ZZ and: wq! functions like
: Q exit
: q! Force exit
Note:
There is also a command, the "." Command, which serves to repeat the previous command.
Linux Learning Commands (1)------VI text Editor