Vim command collection
Command history
Commands starting with ":" and "/" have historical records. You can first type ":" or "/" and then press the up or down arrow to select a historical command.
Start Vim
Enter the following command in the command line window:
Vim directly starts Vim
Vim filename open vim and create a file named filename
FILE command
Open a single file
Vim File
Open multiple files at the same time
Vim file1 file2 file3...
Open a new file in the vim window
: Open File
Open a file in a new window
: Split File
Switch to the next file
: Bn
Switch to the previous file
: BP
View the list of currently opened files. The files being edited are included in.
: ARGs
Open a remote file, such as ftp or share folder.
: E ftp: // 192.168.10.76/abc.txt
: E \ qadrive \ test \ 1.txt
Vim Mode
In normal mode (Press ESC or Ctrl + [enter). The file name is displayed in the lower left corner or is empty.
Insert mode (press the I key to enter) display in the lower left corner -- insert --
Visual mode (do not know how to enter) display in the lower left corner -- Visual --
Navigation command
% Matching brackets
INSERT command
I insert before the current position
I insert at the beginning of the current row
Insert a after the current position
A is inserted at the end of the current row.
O insert a row after the current row
O insert a row before the current row
SEARCH Command
/Text Search Text, search for the next one by njian, and search for the previous one by njian.
? Text Search Text, reverse search, search for the next one by the N key, and search for the previous one by the N key.
Some special characters in VIM need to be escaped during search. * [] ^ % /?~ $
: Set ignorecase case-insensitive search
: Set noignorecase case-insensitive search
Search for a long word. If a word is long and difficult to type, you can move the cursor over the word and press the * or # key to search for the word, which is equivalent to/search. And # The command is equivalent? Search.
: Set hlsearch highlights the search results. All results are highlighted, rather than displaying only one match.
: Set nohlsearch disable highlighted search display
: Nohlsearch disables the current highlight. If you search again or press the N or n key, it is highlighted again.
: Set incsearch gradually searches for the currently typed characters without waiting for the completion of the typing.
: Set wrapscan: Re-searches. When the file header or tail is searched, the system returns to continue searching. This function is enabled by default.
Replacement command
RA replaces the current character with a, and the current character is the character where the cursor is located.
S/old/new/Replace new with old to replace the first match of the current row
S/old/new/g Replace new with old, replace all matches of the current row
% S/old/new/Replace new with old, replace the first match of all rows
% S/old/new/g Replace new with old, replace all matching
: 10, 20 s/^ // G add four spaces in front of each row in 10th rows to indent.
DDP switches the row of the cursor and the row next to it.
Move command
H shifts one character to the left
L shifts one character to the right. This command is rarely used and is generally replaced by W.
K move one character up
J. Move one character down
The preceding four commands can be used with numbers. For example, 20 J means moving 20 lines down and 5 characters to the left for 5 hours. In vim, many commands can be used with numbers, for example, you can delete 10 characters (10 x) and insert 3 after the current position !, 3A! <ESC>, the ESC here is required, otherwise the command does not take effect.
W moves a word forward (cursor stops at the word header). If it is at the end of the line, it is transferred to the beginning of the next line. This command is fast and can replace the l command.
B: move one word backward. 2b: move two words backward.
E, W, but the cursor stops at the end of the word.
GE, the same as B, the cursor stops at the end of the word.
^ Move to the first non-blank character in the row.
0 (number 0) Move to the first character of the row,
<Home> move to the first character of the row. Same as 0.
$ Move to the end of a row 3 $ move to the end of the following three rows
Gg moves to the file header. = [[
G (SHIFT + G) moves to the end of the file. =]
The F (FIND) command can also be used to move. FX finds the first character X after the cursor, and 3fd finds the third character D.
F is the same as f, and reverse lookup is performed.
Jump to the specified row, colon + row number, and press Enter. For example, to jump to row 240, press ENTER 240. Another method is to jump to the row number + G, for example, 230g.
CTRL + e scroll down a row
CTRL + y scroll up a row
CTRL + D scroll down the half screen
CTRL + u scroll up half screen
CTRL + F scroll down one screen
CTRL + B scroll up one screen
Undo and redo
U undo)
U undo the entire row
CTRL + R Redo (redo), that is, the Undo.
DELETE command
X Delete the current character
3X Delete the current cursor starting with three characters backward
X deletes the first character of the current character. X = DH
DL deletes the current character, DL = x
DH deletes the previous character
Dd deletes the current row
DJ deletes the previous row
DK deletes the next row
Delete 10 rows starting with the current row within 10 days.
D. Delete the current character to the end of the line. D = d $
D $ Delete All characters after the current character (ROW)
Kdgg deletes all rows before the current row (excluding the current row)
Jdg (jd shift + G) deletes all rows after the current row (excluding the current row)
: 1, 10 days delete 1-10 rows
: 11, $ D Delete 11 rows and all subsequent rows
: 1, $ D delete all rows
J (SHIFT + J) deletes empty rows between two rows, which are actually merged.
Copy and paste
YY copy the current row
Nyy copies the N rows starting from the current row, for example, 2yy copies the current row and the next row.
P is pasted after the current cursor. If you have used the YY command to copy a row, paste it in the next row of the current row.
Shift + P paste in front of current row
: 20th Co 20 insert 1-10 rows to rows.
: 1, $ Co $ copy the entire file and add it to the end of the file.
In normal mode, press V (verbatim) or V (line-by-line) to enter the visual mode. Then, use the jklh command to move and select certain lines or characters. Then press y to copy them.
DDP exchange the current row and next row
XP exchanges the current character with the next character
Cut command
In normal mode, press V (verbatim) or V (line-by-line) to enter the visual mode. Then, use the jklh command to move and select certain lines or characters. Then press d to cut.
NDD cut the N rows after the current row. The p command can be used to paste the cut content.
: 1, 10 days Cut 1-10 rows. The p command can be used to paste the cut content.
: 1, 10 m 20 move rows 1-10 to rows 20th.
Exit command
: WQ save and exit
ZZ save and exit
: Q! Force exit and ignore all changes
: E! Discard all modifications and open the original file.
Window command
: Split or new opens a new window, And the cursor stops at the top-level window
: Split file or: New file open the file in a new window
The split window is displayed horizontally. You can use vsplit to open the window vertically.
CTRL + WW move to the next window
CTRL + WJ move to the window below
CTRL + wk move to the window above
Close Window
: You cannot use this command to close the last window to prevent accidental exit of vim.
: Q if it is the last closed window, it will exit vim.
ZZ save and exit.
Close all windows and keep only the current window
: Only
Recording macro
Press the Q key and add any letter to start recording, and then press the Q key to End recording (which means That Macros in VIM cannot be nested). When using the Q key, @ add macro name, such as QA... Q: The recording name is a macro. @ A uses this macro.
Execute shell commands
:! Command
:! Ls to list files in the current directory
:! Perl-C script. pl check the Perl script syntax. It is very convenient to exit vim.
:! Perl script. Pl: It is very convenient to execute a Perl script without exiting vim.
: Suspend or Ctrl-Z suspends vim and returns to shell. Press FG to return vim.
Comment command
In the Perl program, # The Beginning of the behavior annotation, so to comment some rows, you only need to add at the beginning of the line #
3, 5 S/^/#/g comment line 3-5
3, 5 S/^ # // G uncomment 3-5 rows
1, $ S/^/#/g comment the entire document.
: % S/^/#/g to comment out the entire document. This method is faster.
Help commands
: Help or F1 displays the entire help
: Help XXX displays the help of XXX, for example: help I,: Help Ctrl-[(that is, CTRL + [help ).
: Help 'number' the vim option is enclosed in single quotes
: Help <ESC> help for special keys <> Expand
: Help-t help for VIM startup parameters-
: Help I _ <ESC> help of ESC in insert mode, help mode in a mode _ TOPIC Mode
The content in the Help file is a hyperlink. You can press Ctrl +] to enter the link, and press Ctrl + O (CTRL + T) to return
Other non-edit commands
. Repeat the previous command
: Set rtasks? Check whether rsequence is set. In. vimrc, you can use this command to view the set options.
: Scriptnames: view the location of the vim script file, such as The. vimrc file, syntax file, and plugin.
: Set list displays non-printable characters, such as tab, space, and end of line. If the tab cannot be displayed, use the set LCS = tab:>-command to set it. vimrc file, and make sure that there is a tab in your file. If expendtab is enabled, the tab will be expanded to a space.
Vim tutorial
On UNIX systems
$ Vimtutor
On Windows
: Help tutor
: Syntax list defined syntax items
: Syntax clear defined syntax rules
: Syntax case match is case sensitive. int and INT are considered different syntax elements.
: Syntax case ignore is case-insensitive. int and INT are treated as the same syntax elements and use the same color scheme.