First, Vim common operation
1. Insert command
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 under the cursor
2. Positioning commands
: Set UN set line number
: Set noun 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
3. Delete command
X Delete the character at cursor location
NX removes the n characters after the cursor is located
DD deletes the cursor in the row
NDD Delete N rows
DG Deletes the contents of the cursor line to the end of the file
D Delete the contents of the cursor at the end of the line
: n1,n2d deletes a specified range of rows
4. 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 Pastes the next line in the row where the current cursor is located
P Pastes the previous row of the current cursor
5. Commands to replace and cancel
R replaces the character at which the cursor is located
R replaces the character at the beginning of the cursor and presses the ESC key to end
U Cancel the previous action
6. Search or Replace
/string where string is the string you want to search for, the search is case-insensitive: Set IC
n Search for where the next character appears
:%s/old/new/g Replacement string
: N1,n2s/old/new/g replaces characters within a specified range
7, save and Save As command
: W Save changes
: W newfile Save as specified path file
ZZ Save changes and exit
: q! does not save changes and exits
: wq! force Save changes and exit (the file owner and root can be used)
Second, the use of VIM skills
1. import file contents and command results
: r/etc/111 the output of the import file to the cursor location
: R! Command Import command execution results to cursor location, such as: R!cat/etc/redhat-release
2. Define shortcut keys
: Map ^p i#<esc> Note ^p is at the same time holding down ctrl+v+p settings, P is to set the shortcut key i#<esc> means to insert # at the beginning of the line and back to command mode, you can also press CTRL + V, and then press Ctrl+p to set, when using shortcut keys
Can be used with ctrl+p.
3, continuous Comment line
: N1,n3s/^/#/g N1,n3 represents the first and 3rd lines, ^ represents the beginning of the line, meaning to add the beginning of 1-3 lines #
: AB mymail [email protected] Replace
The above once the server restarts, all of the set of fast keys will be invalidated, we can write it into the configuration file, in the current user's home directory to create a new VIMRC, as the root user example
In VIM/ROOT/.VIMRC
Set Nu
Map ^p i#<esc>
Vim Usage Tips