1. Introduction
Vim is a powerful full-screen text editor that is the most commonly used text editor on Linux/unix.
Vim has no menu, only commands
2. Working mode
Enter: VI filename
Enter insert mode:
A specifier insert in the word cursor
A at the end of the line where the cursor is inserted
I match either insert in the word cursor
I Insert at the beginning of the line where the cursor
o Insert a new line under the cursor
O insert a new line on the cursor
Enter Command mode: ESC or:
Locate command:
: Set Nu Sets line number
: Set Nonu Cancel line number
GG to First line
G to last line
NG to Nth row
: N to Nth row
$ move to end of line
0 move to the beginning of the line
Delete command:
x Delete the character of the cursor
NX removes the second n characters at the cursor location
DD Delete cursor navigation, NDD delete n rows
DG deletes the line from the cursor to the end of the file
D Delete the cursor at the end of the line
: n1,n2d deletes a specified range of rows
Copy and cut commands:
YY copy when moving forward
Nyy Copy the current row following n rows
DD Cut when moving forward
NDD cuts the current row following n rows
P/p pasted at the current cursor row or line
To replace or cancel a command:
R replaces the character at which the cursor is located
R replaces the character at the beginning of the cursor and presses ESC to end
U Cancel the previous action
Search and search Replacement commands:
/string search for specified string, ignoring case when searching: Set IC
n searches for the next occurrence of the specified string
:%s/old/new/g full text Replace specified string
: N1,n2s/old/new/g replaces specified string within a certain range
Save and Exit Commands:
: W Save changes
: W new_filename Save as specified file
: Wq Save and exit
ZZ shortcut keys, save changes and exit
: q! Do not save changes to exit
: wq! Forcibly save the changes and exit (the file is used by the user and root)
3.Vim Usage Tips
Import command execution result: R! command
: R filename Imports the contents of the file to the current file cursor position
: System command does not exit the current file when the system command is executed
Examples of use:: R! command to import the execution result of the command into the current file
Define shortcut keys: Map shortcut Trigger command
: Map crtl+v+p i#<esc>: Jump to the beginning of the line Insert # # (add comment) Keep in command mode
: Map crtl+v+b 0x: Skip to First line delete first character
Continuous line comments:
: n1,n2s/^/#/g: Add comments at the beginning of the line without prompting
: n1,n2s/^/#//g: Delete the # comment at the beginning of the line
: n1,n2s/^/\/\//g: Add two//notes to the beginning of a line
Definition substitution: AB mymail [email protected]
Enter MyMail carriage return in the file and change to the corresponding mailbox
2016/8/19 5.1 Text editor Vim-vim common operations