Vim commands Collection
Command History
To: and / beginning commands have history, you can type the first: or / and then press the down arrow to select a command history.
Start vim
Enter the following command in the command line window to
[root@mylab]# vim
vim filename open vim or create a file named filename
[root@mylab]# vim filename
File Commands
Open a single file
[root@mylab]# vim file
Simultaneously open multiple files
[root@mylab]# vim file1 file2 file3 ...
Open a new file in vim window
:open file
Open the file in a new window
:split file
Switch to the next file
:bn
Switching to a file
:bp
View a list of files that are currently open, the file currently being edited will use the [] brackets.
:args
Open remote files, such as ftp or share folder
:e ftp://192.168.11.56/vim.txt
:e \\drive\test\vim.txt
vim mode
Normal mode (press Esc or Ctrl + [ enter) the lower left corner displays the file name or is empty
Insert mode (Press the i key) lower left corner of the display --INSERT--
Visual mode (Press the v or V key on the Normal mode) lower left corner of the display --VISUAL--
Navigation commands
-------------------
% Matching brackets
Insert command
i lifetime inserted at the current location
I first inserted in the current line
a is inserted after the current location
A row is inserted at the end of the current
o insert a row after the current row
O Insert a row before the current row
Find command
/ Text Find text, press n Kin Find Next to find a former press N health.
? Text Find text, reverse lookup, press n Kin Find Next to find a former press N health.
vim has some special characters need to be escaped when looking for. * [] ^% /? ~ $
:set ignorecase ignoring case
:set noignorecase not ignoring case
Find a long term, if a word is very long, type of trouble, you can move the cursor to the word, press * or # key to be able to search for the word, which is equivalent / Search. The # command is equivalent to? Search.
:set hlsearch highlighted search results, all results are highlighted, and not only show a match.
:set nohlsearch Close highlighted search display
:nohlsearch Close the current highlighted, if the re-search or press the n or N keys will highlight again.
:set incsearch gradually search mode, the characters typed on the current search without having to wait for typing complete.
:set wrapscan search again, in search of the file header or trailer, the return to continue the search, enabled by default.
Replace command
ra will replace the current character is a, the current character is the character of the cursor.
s/oldstr/newstr/ replaced the newstr with the oldstr, replace the first match of the current row
s/oldstr/newstr/g replaced the newstr with the oldstr, replace all occurrences of the current row
%s/oldstr/newstr/ replaced the newstr with the oldstr, replace the first match of all rows
%s/oldstr/newstr/g replaced the newstr with the oldstr, replacing the all matching of the file
:10,20 s/^/ /g Add four spaces at the front and tenth lines to the thirtieth line to the line.
ddp Swap line and its adjacent next row.
Move Command
h move one character to the left
l move one character to the right, this command is rarely used, usually with w instead.
k move up one character
j move down one character
These four commands can be used with numbers, For example, 20j is down to move the 20 line, 5h is left to move 5 characters, in Vim, a lot of commands can be used in conjunction with the number, such as deleting 10 characters is 10x.
w move forward one word (cursor in the header word).
b move backward one word,2b move backward two words.
e with w, just the tail of the cursor in the word
ge with b, the cursor in the word tail.
^ Move to the first non-blank character.
0 (number 0) to move to the first character of the Bank,
$ to move to the end of the line
3$ to move to the lower end of the line 3
gg moves to the file header. = [[
G (shift g) to move to the end of the file. = ]]
f (find) command can also be used to move, fx the first character is x, 3fd will find a third to d characters found after the cursor.
F with f, reverse lookups.
Jump to a specific row, the colon line number, enter, for example, jumps to 240 lines is: 240 Enter.
Ctrl + e scroll down one line
Ctrl + y scroll up one line
Ctrl + d scroll down half a 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 operations on an entire row
Ctrl + r Redo (Redo).
Delete command
x Delete current character
3x delete the current cursor start back three characters
X to delete a character before the current character. X = dh
dl delete the current character, dl = x
dh to delete a character before the current character.
dd Delete the current line
dj Remove the last line
dk Remove the next line
di [tag]
For example, put the cursor on the beginning of the parenthesis, use the following commands to delete text in parentheses:
di ( or di { or di " Remove the specified contents of the previous mark And remove the tag inside is somewhat similar, but different purposes. Command is as follows:
dt [tag] Deletes the contents of all between point and mark (holding tag does not move), if the mark in the same line of words. E.g
dt. Deletes to the end of the sentence, but keep '.' Does not move.
10d Remove from the beginning of the current line of 10 row.
D delete the current character to the end of the line. D = d$
d$ delete the current character to the end of the line.
kdgg delete all the rows before the current row (excluding the current row)
jdG (jd shift g) Remove all lines after the line that the current (excluding the current row)
:1,10d delete lines 1-10
:11,$d deleted 11 lines and all subsequent rows
:1,$d Delete all lines
J (shift j) Remove empty lines between the two lines is actually two lines merge.
Copy and Paste
yy copy of the current row
nyy copy of the current row began after n, such 2yy copy of the current line and the next line.
p at the current cursor after pasting, if before using the yy command to copy a row, then paste it in the next line of the current line.
shift + p paste before the current row
:1,10 co 20 rows into the 1-10 after the first 20 rows.
:1,$ co $ will copy the entire file and added to the end of the file.
Under normal mode, press v (literally) or V (progressive) into the Visual mode, then use jklh command to move to select certain lines or characters, and then press y to copy
ddp switching current line and the next line
xp switching current character and the subsequent character
Cut command
Under normal mode, press v (literally) or V (progressive) into the Visual mode, then use jklh command to move to select certain lines or characters, then you can cut d
ndd cut n line after the current line. You can use the p command to paste the contents of the cut
:1,10d cut the lines 1-10. By p command to paste the contents after shearing.
:1,10 m 20 lines 1-10 will move to after the first 20 rows.
Exit command
:wq to save and exit
ZZ Save and Exit
:q! and ignore all the changes forced exit
:e! discard all changes and open the original file.
Window command
:split or new to open a new window on the cursor at the top of the window
:split file or :new file open the file in a new window
split open windows are horizontal, use vsplit longitudinally open the window.
Ctrl + ww move to the next window
Ctrl + wj moved to the bottom of the window
Ctrl + wk move to the top of the window
close the window
:close the last window can not use this command, you can prevent accidental quit vim.
:q If this is the last window is closed, it will quit vim.
ZZ save and exit.
Close all windows, leaving only the current window
:only
Record Macro
Press the q key plus any letter to start recording, press q key to end the recording (which means that macros can not be nested in vim), when using the @ plus macro name, such as qa. . . q record a macro named, @a use this macro.
Execute shell commands
:!Command
:!ls lists the files in the current directory
:!perl -c script.pl perl script syntax checking, you can not quit vim, very convenient.
:!Perl script.pl execute perl scripts, you can not quit vim, very convenient.
:suspend or Ctrl - Z suspend vim, back shell, press fg to return vim.
Comment Command
perl program beginning with # are comments, so some of the lines to be annotated, just join the line first #
3,5 s/^/#/g Comment Lines 3-5
3,5 s/^#//g uncommented lines 3-5
1,$ s/^/#/g Comment the all lines
:%s/^/#/g Comment the all lines, this method is faster.
Help command
:help or F1 to display the entire help
:help xxx to display xxx help, such as: help i,: help CTRL - [.
:help 'number' help Vim option in single quotes
:help help special bond with <> spread from
:help help -t Vim startup parameters used -
:help i_<Esc> Insert mode Esc help, help with the mode of a mode _ themed mode Contents || Help file is located between the hyperlink, you can use Ctrl] to follow the link, Ctrl o (Ctrl t) Returns
Other non-editing commands
. repeat the last command
:set ruler? to see if the set ruler, in .vimrc, use the set command to set up the system options can be viewed by this command
:scriptnames view the location of vim script file, such .vimrc files, syntax files and plugin like.
:set list display non-printing characters, such as tab, space, and other end of the line. If the tab is not displayed, make sure to use set lcs = tab:> - command sets the .vimrc file, and make sure your file is indeed a tab, if turned expendtab, then the tab will be expanded to spaces.
Vim Tutorials
On Unix systems
$ vimtutor
On Windows systems
:help tutor
:syntax list syntax items that have been defined
:syntax clear clear syntax rules defined
:syntax case match is case-sensitive, int and Int will be treated as a different syntax elements
:syntax case ignore case insensitive, int and Int will be treated the same syntax elements, and use the same color scheme