Vim Common shortcut keys

Source: Internet
Author: User

1, Vim ~/.VIMRC Enter the configuration file
If you don't know where the VIMRC file is, you can use the: Scriptnames to view
Set Nu #行号
Set tabstop=4 #一个tab为4个空格长度
Set AI? #设置自动缩进
Syntax on?? #高亮
?
2. Basic
SPACEBAR to move one cell to the right
X Delete the following character x delete the previous character? Delete 3 characters is 3x??
DD: Delete one line?? D Delete to end of line?
CAW: Rewrite the word? C is equivalent to D into edit mode
J: Remove line breaks to make the next line come up.???? NJ: Connecting the following n rows
U: Undo last Action????? U: Undo all changes to the current line
Ctrl+r: Undo for Undo
I insert before the cursor
I Insert at the beginning of the line?
A after the cursor is inserted
A inserts at the end of A row
O: Another line below the current line and becomes insert mode
O: Another row above the current line, into insert mode
Ctrl+o: Temporarily into command mode (only once)
: e!: Discard Changes and then re-open
: Help: assistance, using ZZ to exit the Help window
Nyy in vim can copy the n rows after the cursor. Sometimes it is not easy to get a number of trips, which can be used as a marker to define the scope of replication:

1. Enter the MA on the start line as a marker a

2. Move to the end line, and enter Y ' A to copy the text between the current line and the mark A. d ' A will be deleted.

or V into the visual mode, then 13G jump to the corresponding line, Y can.
: 10,20y??? Enter, the corresponding deletion is the same???? : 10,20d???? (This method is simpler than both of the above methods)
: 10,20 m??? Cut the contents of lines 10 through 20 to 30 rows
: 10,20 Co 30?? After copying the contents of rows 10 to 20 to 30 rows
Place your cursor in the? {?, and then enter v% to select the contents of the curly braces.
If the cursor is placed on the first s, and you want to delete to "(", then enter DT (it is OK, t (the function is to skip to the next "(").
CTRL +n Auto-complete CTRL + P as well
: AB HW Hello world? Use an abbreviated string instead of a long string, where HW is used instead of the Hello World
%: Move to the bracket matching with the system up (),{},[],<> etc.
' Move to the last modified row
FX jumps right to the bank character X (x can be any character)
Fx jumps left to bank character X (x can be any character)
TX and FX are the same, the difference is jumping to the character x before
Tx and FX are the same, the difference is after jumping to the character X
# to the previous word that is the same as the current word, * to the next word that is the same as the current word
If you want to type a phrase or a sentence repeatedly, there is a quick way. Vim has a mechanism for recording macros. You type "QA" to start recording a macro into the register variable ' a '.
Press down you can type the action you want as usual, but these actions will be recorded by Vim in the macro named ' a ', and then the "Q" Key again to end the macro ' a ' recording. When you want to repeat the actions you just recorded, just use the "@a" command. There are 26 registers available for you to record macros. You can repeat several different actions by using a macro. Instead of just inserting text. If you want to do something repetitive, remember to use this trick.
: Abbr hte the
: abbr HW Hello World
When you enter a first-face word, it is replaced automatically with the following.
?
3. Mobile:
B, 3b, W, 3w: Move forward a few words, punctuation is also counted as a word. The corresponding uppercase state is free of punctuation, that is, only spaces and line breaks are used as word spacers.
$: Move to end of line? 3$: Move to end of line after 3 lines
^: Move to the beginning of the line, 0 is also
+: Move to the beginning of the next line
-: Move to the beginning of the previous line
F: Search command, lower case backward search (used to locate) such as FX: Navigate to the next X. Fx: Navigates to previous X, when duplicated, available; However, the opposite direction is indicated
%: Jumps to the corresponding parentheses, commonly used in programming
33G: Jump to 33 lines?? Press ' to return to the original line
GG: file header?? G: End of File
30%: Jump to 30% of files
"H" means home, "M" for Middle, "L" for last. The upper and lower position of the current screen, and the case can be
Ctrl+g: Show Current position
Set Number: Sets display line numbers, set Nonumber: Turn off display
: Set ruler to display line numbers in the lower right corner of the window, with the benefit of the above, space saving
Ctrl+u\d? Scroll up/down half screen
Ctrl+e\y? Scroll up \ down one line
Ctrl+b\f? Scroll up \ Down one screen this is more practical, remember.
ZZ: Scrolls the current line in the middle of the screen for easy viewing of the context? ZT pinned, ZB tail
/string? Find a string, enter, press N to jump to the next, N, another press/key, press the up and down keys to find the previous search records, the same: there are records
?/string Ibid, default up lookup
: Set ignorecase case insensitive
: Set Noignorecase Case sensitive
*: Find the word next to the cursor? #是查找上一个
: Set Hlsearch? Highlight Find Results
: Set Nohlsearch? Cancel highlighting
: Nohlsearch? Remove the high end of the current display (disposable)
? ' last row where the cursor was docked
% matches to corresponding brackets
>>?? Move the bank to the right for some distance???? <<?? Move the bank to the left for some distance??? 3<<??? Move the following 3 lines (including the bank) to the left for a distance???? : 20,30>>? Move 20 lines to 30 lines to the right for a distance
?
4. Minor changes:
:%s/str1/str2/g?? replace each row with a str1 of str2
: 10,20s/str1/str2/g? Replace str1 from line 10 to line 20 for STR2
: Ten, $s/str1/str2/g?? Replace the str1 from line 10 to the last row as str2
: s/str1/str2/g?? Replace the current line with a str1 of str2
.?? Repeat the command?
: 10,$ w test2.cpp???? Row 10 to last row, save to Test2.cpp
: R CLASS/USER.HPP??? Reads the contents of a file, inserted after the current line
DW: Delete a word (after the cursor part)?     Why: Daw practical d4w: Delete 4 words d$: Delete the current cursor to the end of the line d^: Delete the current cursor to the beginning of the row?? D change to C effect is the same, but after the operation will become insert mode?? DNW: delete n words?? DNJ: delete n rows down????? DNK: delete n rows up?
X: Delete left character, equivalent to <-key, x delete current character D: equivalent to d$ C: equivalent to $ S: equivalent to C1 s: equivalent to CC
R: Replaces the current character, but does not enter insert mode 3r: Replace the following 3 characters with R: Replace mode
.: Repeat Last Action
V: Enter visual Mode V: Enter visual line mode, such as VJJD? Delete 3 Rows Ctrl + V: Visual block mode
P: Paste to the cursor before P: Paste to Cursor 3 p: Paste 3 times????? "2p???? Paste the last deleted content for the second time
YY: Copy one line yaw: Copy a word, and the cursor is anywhere in the word??? YNW: copy n words?????? YNJ: Copy n rows down????????? Ynk: Copy n rows up??
Auto indent:
: Set Cindent (all sets can be abbreviated to SE, although only one character is saved, the translator notes) It is important to note that the Cindent control indent is through the value of the Shiftwidth option, instead of the TabStop value, the default value of Shiftwidth is 8 ( That is, a indentation of 8 spaces, the translator note), to change the default settings, you can use the ": Set shiftwidth=x" command, where x is the number of spaces you want an indent to represent.
? {= To the previous empty line
} = to the next empty line
?
? 5, some of the VIM plug-ins:
C.vim: If it is the root account, the file copied to the/usr/share/vim/vim70 extract no use, there is no $HOME/.vim this directory, no way, can only create a new directory, and then the compression packet CP to this directory, and then unzip can. Write filetype plugin on in ~/.VIMRC?
?
: E!?? Returns the state after the last save
CTRL + Z: Pause VI, return to the UNIX prompt, and then enter FG to return to VI.
^ Back to the beginning of the line, the cursor is at the beginning of the line, 0 back to the beginning, the cursor before the beginning letter. $ returns to the end of the line with the cursor at the end of the line.
NB: move n words forward, NW: move n words backwards. The cursor is at the first letter of a word. NW This operation is very slow, somehow. delimited by spaces, punctuation marks, and word boundaries. (several consecutive punctuation are treated as one word)
Similarly, you can use NB,NW, but only spaces are used as separators.
Swap two adjacent letters in position: X, p
S: Delete one character and enter edit mode. S: Delete A whole line, enter the edit mode, equivalent to CC.?? NS: Delete the next n characters and enter edit mode.
~: Change the case of the letter while the cursor enters the next character. n~: Change the case state of the back N letters.
DW: Delete the following part of the word???? DB: Delete the previous part of the word.? If you want to delete the entire word (the cursor is in the middle of the word), you can dbw\wdb
De: Similar to DW, delete the part after the word (delete only to the end of this word, DW will delete the space after the word)?? DE: The deleted range includes the end of the word, including the label.
E: Equivalent to W, moving backwards one word. The difference is that W moves to the first character of the word, and e moves to the last character of the word. So the EA can add content to this word.
The shorthand of d:d$, the same, the shorthand of c:c$.
U: Will restore a whole line of the original appearance, that is, the most primitive appearance.
Y: Equivalent to YY, different from the operation method of D and C.
.: Repeats the previous command.
In addition to o/o, the Insert command (a,a,i,i) accepts numeric parameters, such as: 5Ihello, and then presses the ESE key. Will enter 5 connected Hello at the beginning of the line
NR: replaces the following n characters.
NJ: Merges the following n lines (from the bank).
YNL: copies n characters backwards.
E/E: To the end of the word.

?
Scrolling Full Screen:
^f: Forward (down) a full screen
^b: Back (UP) a full screen
^d: Forward (down) half screen
^u: Back (up) half screen
Z,enter: Moves the line of the cursor to the top of the screen (same as ZZ)
Z.: Moves the line of the cursor to the middle of the screen
Z: Moves the line of the cursor to the end of the screen
Nz,enter: Moves the nth line to the top of the screen, similarly, Z. and Z-front can also be added to the number.
?
To move through the screen:
H, M, L move to the top, middle, and tail of the screen, respectively.
NH, NL moves to the top of the screen and the top n row position.
?
? Enter: The first character to the next line.
+: The first character to the next line.
-: To the first character of the previous line.
n|: Move to nth column of the current row
E: Move to the end of the word
E: Move to the end of the word (ignore punctuation)
(?? )?? {?? }? [[? ]] These few have little effect on programming and can be ignored.
D/it: Backward to the location before it (it is not deleted).??? D?it: Move forward to the location before it (remove it).
?
? FX: We search for X to the right and the cursor is placed on X. Fx: Search left.; Repeat the previous search command in the same direction.?? , repeat the previous search command in the opposite direction.
TX: Same as FX, just before the cursor is placed in X. TX is similar.
DFI: Delete the position of the first I (including i) to the right? DTI: With DFI, just not including I
Ctrl+g View Current line information
Ng jumps, you can use the ' go back to last position, ' function, but just go back to the beginning of the row where the previous position was, not the position you identified.
?
Delete the line containing the keyword string:?: g/keyword/d
Delete blank line::%s/^\n$//g

Vim Common shortcut keys

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.