Vim Command Collection
Command History
Commands with: and/start with history, you can first type: or/And then press the up and down arrows to select a history command.
start Vim
Enter the following command in the Command line window
Vim starts vim directly
Vim filename opens vim and creates a file named filename
file Commands
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 previous file
: BP
View the list of currently open files, and the files currently being edited are enclosed 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's mode
Normal mode (press ESC or ctrl+[to enter) to display the file name or empty in the lower left corner
Insert mode (press I key to enter) the lower left corner shows--insert--
Visual mode (do not know how to enter) the lower left corner shows--visual--
Navigation Commands
% Bracket Match
Insert Command
I inserted before the current position
I inserts at the beginning of the current line
A inserts after the current position
A inserts at the end of the current line
o Insert a row after the current line
O insert a row before the current line
Find Command
/text find text, press N to find Next, and press N to find the previous one.
? text find text, reverse lookup, press N to find Next, press N to find the previous one.
Some special characters in vim need to be escaped when searching. *[]^%/?~$
: Set ignorecase Ignore Case lookup
: Set noignorecase do not ignore case-insensitive lookups
Look for long words, if a word is very long, typing trouble, you can move the cursor to the word, press * or # key that word can be searched, the equivalent of/search. And the # command is equivalent to a search.
: Set Hlsearch Highlight search results, and all results are highlighted rather than just one match.
: Set Nohlsearch off highlight search display
: Nohlsearch closes the current highlight, and if you search again or press N or N, it will be highlighted again.
: Set Incsearch a step-by-step search pattern that searches for the characters currently typed without having to wait for typing to complete.
: Set Wrapscan to search again, when searching to the header or tail of the file, return to continue the search, the default to open.
Replace command
The RA replaces the current character with a, where the period character is the character of the cursor.
S/old/new/replaces new with old, replaces the first match of the current line
S/old/new/g replaces new with old, replaces all matches for the current line
%s/old/new/replaces new with old, replaces the first match for all rows
%s/old/new/g replaces new with old and replaces all matches for the entire file
: 10,20 s/^//g in line 10th know the 20th line in front of each line plus four spaces, for indentation.
The DDP exchange cursor is in line with the row immediately below it.
Move Command
H move one character to the left
L Move one character to the right, this command is rarely used and is generally replaced with W.
K Move one character up
J Move one character down
The above four commands can be used with digital, such as 20J is to move down 20 lines, 5h is to move to the left 5 characters, in vim, many commands can be used with digital, such as the deletion of 10 characters 10x, in the current position after inserting 3. , 3a. <esc>, the ESC here is required, otherwise the command does not take effect.
W moves one word forward (the cursor stops at the word header), and if it is at the end of the line, go to the beginning of the next line. This command is quick and can replace the L command.
b Move one word back 2b move 2 words back
E, same w, just the cursor stops at the end of the word
GE, with B, the cursor stops at the end of the word.
^ Move to the first non-white-space character on the bank.
0 (the number 0) moves to the first character of the Bank,
<HOME> move to the first character of the bank. With 0 kin.
$ move to end of line 3$ move to line end of line 3 below
GG moves to the header of the file. = [[
G (Shift + g) moves to the end of the file. = ]]
The f (find) command can also be used to move, FX will locate the first character after the cursor, and the 3FD will find the third character for D.
F with F, reverse lookup.
Jump to the specified line, colon + line number, enter, such as jump to 240 lines is: 240 back to the car. Another method is line number +g, such as 230G jumping to 230 rows.
Ctrl + e scroll down one line
Ctrl + y scroll up one line
Ctrl + D scroll down 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 (undo)
U undo action on Whole line
Ctrl + R Redo (Redo), that is, undo revocation.
Delete command
X Delete Current character
3x Delete current cursor start backwards three characters
X deletes the previous character of the current character. X=dh
DL deletes the current character, dl=x
DH Deletes the previous character
DD Delete when forward
DJ Deletes previous line
DK Delete Next Line
10d deletes 10 lines starting at the current line.
D deletes the current character to the end of the line. d=d$
d$ Delete all characters after the current character (line)
KDGG all rows (excluding current rows) before the current row is deleted
JdG (JD Shift + G) deletes all rows after the current line (excluding current rows)
: 1,10d Delete 1-10 lines
: One, $d delete 11 lines and all subsequent lines
: 1, $d delete all rows
J (Shift + J) deletes the blank line between the two lines, actually merging the two rows.
Copy and paste
YY copy when moving forward
Nyy copies the current start of n lines, such as the 2yy copy of the current line and its next line.
P Pastes after the current cursor, if the YY command was used to copy a row, then the next line in the current row is pasted.
Shift+p Paste before current line
: 1,10 Co 20 inserts 1-10 rows after line 20th.
: 1,$ Co $ copies the entire file and adds it to the tail of the file.
In normal mode, press V (verbatim) or V (line by row) into visual mode, then move with the JKLH command to select some rows or characters, and then press Y to copy
DDP Exchange Current line and its next line
XP swaps the current character and then one character
Cut Command
In normal mode, press V (verbatim) or V (line by row) into visual mode, then move with the JKLH command to select some rows or characters, and then press D to cut
NDD cut n rows after the current row. Use the P command to paste cut content
: 1,10d will cut 1-10 lines. Use the P command to paste the cut content.
: 1 m 20 moves the 第1-10 line after line 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 window where the cursor stops at the top window
: Split files or: New file opens with a newer window
Split open windows are horizontal, using Vsplit to open the window vertically.
CTRL+WW move to the next window
CTRL+WJ move to the bottom of the window
Ctrl+wk move to the top window
Close window
: The last window of close cannot use this command to prevent an unexpected exit from Vim.
: Q If it is the last window to be closed, then the vim will be exited.
ZZ Save and exit.
Closes all windows, leaving only the current window
: Only
Recording macros
Press Q and add any letter to start recording, and then press Q to end recording (this means that the macro in Vim can not be nested), when used @ Add macro name, such as QA ... Q record A macro named A, @a use this macro.
Execute shell Command
:!command
:!ls list files in current directory
:!perl-c script.pl Check the Perl scripting syntax, and it's easy to quit Vim.
:!perl script.pl to execute Perl scripts, which can be very handy without exiting Vim.
: Suspend or Ctrl-z hang vim, back to the shell, according to FG can return vim.
Comment Command
The behavior annotation in the Perl program # starts, so to annotate some lines, just add the # at the beginning of the line
3,5 s/^/#/g annotation 第3-5 line
3,5 s/^#//g 3-5-line Comment
1,$ s/^/#/g annotate the entire document.
:%s/^/#/g annotate the entire document, this method is faster.
Help Commands
: Help or F1 displays the entire aid
: Help XXX Displays the assistance of XXX, such as: Help I, helping ctrl-[(that is, ctrl+[).
: Help ' number ' vim option is enclosed in single quotes
: Help <Esc> Special key helps with <> expansion
: help-t Vim startup parameters for help-
:helpi_<esc> the help of ESC in insert mode, mode for help in a pattern _ theme
The Help file is located in | | The content is a hyperlink, you can use CTRL +] to enter the link, Ctrl+o (Ctrl + T) return
Other non-edit commands
. Repeat previous command
: Set ruler? Check to see if ruler is set, in. VIMRC, options that are set by using the SET command can be viewed through this command
: Scriptnames View the location of the Vim script file, such as. vimrc files, grammar files, and plugin.
: The set list displays nonprinting characters, such as tab, space, line footer, and so on. If tab cannot be displayed, make sure that the. vimrc file is set with the setlcs=tab:>-command and that you have tab in your file, and that if Expendtab is turned on, the tab will be expanded to a space.
Vim Tutorial
On the UNIX system
$ vimtutor
On the Windows system
: Help Tutor
: syntax lists the syntax entries that have been defined
: syntax clear clears the defined grammar rules
: syntax case match casing sensitivity, int and int will be treated as different syntactic elements
: syntax case ignore case-insensitive, int and int will be treated as the same syntax elements and use the same color scheme