Recently work in need to change files on the Linux server, suffering from the various commands of VIM is not familiar with, today we summarize and familiar with a variety of VIM commands, so as to improve work efficiency. Late Continuous update
Vim Editor Personal settings
- First copy the Vim configuration template to the personal directory
cp /usr/share/vim/vimrc ~/.vimrc
- Edit the. VIMRC in the personal directory.
vi ~/.vimrc
Enter vim edit mode to write the following configuration information
syntax on '开启语法高亮'set nu! '设置行号'set autoindent '自动缩进'set tabstop=4 '设置tab键为4个空格' set showmatch '设置匹配模式,类似当输入一个左括号时会匹配相应的右括号'
Command mode-Execute command
In this mode, you can enter commands to perform multiple functions. Controls the movement of the screen cursor, the deletion of characters, words, or lines, moving and copying a section and entering insert mode, or to last line mode.
Input modes (Insert mode)-Enter text
VI is run, usually in command mode, type the following command to let VI exit the command mode, enter the input mode: I (i), A (a), O (o).
Last line mode-execute pending command
Save or Exit VI, or you can set the editing environment, such as looking for a string, listing line numbers ... such as In general, however, we simplify the VI into two modes when we use it, that is, the last-line mode is also counted in command-line mode.
Command mode common Command Move command
^ Move to the beginning of the current line
$ move to the end of the current line
W moves to the beginning of the next word
GG Move to file header
Shift+g move to end of file
H Cursor Shift Left
J Cursor Move Down
K Move Cursor up
L MOVE the cursor right
Ctrl+b (back) screen moves backward one page
Ctrl+f (forward) screen move forward one page
Ctrl+u (UP) screen move up half page
Ctrl+d (down) screen Move down half page
Undo Command
U Step Backwards
Ctrl+r Redo
Delete command
X Delete Current character
DD deletes the cursor in the row
DGG Delete all characters from the line of the cursor to the file header
DG deletes all characters from the line of the cursor to the end of the file
Copy cut and paste
YY the copy cursor is in the row
P Pastes the copied data on the next line of the cursor
P pastes the copied data on one line of the cursor
. Repeat a previous action
Exit command
: w filename (saved to specified file) Save As
: Q exit
: q! Forcibly exits VI so that the updated content is not written back into the file.
: Wq Save and exit, the two steps above can be synthesized in one step.
: X Save and exit
Search command
/text find text backwards from the cursor, press N to find the next, and press N to find the previous one.
? text looks forward from the cursor to text, press N to find the previous one, and press N to find the next.
Search for special symbols .*[]^%/?~$
to be escaped
: N quickly positions the cursor to n rows
Vim +/text a.php Open the a.php and position the cursor to the first text
% quick positioning to the other half symbol{}[]()
Replace command
R replaces the character of the cursor (press R to enter new characters)
%s/t/o/g Replace all T with O
Modify command c [number] Motion
c^ removes all characters from the current position to the beginning of the current line and enters insert mode
C $ Deletes all characters from the current position to the end of the current line and enters insert mode
Insert command
I insert and switch to input mode before the current position
A insert and switch to input mode after the current position
o Insert a row below the current line and switch to input mode
Press the Insert command to enter text input mode
:! Can execute other shell commands
Vim commands commonly used in the work