VIM frequently used shortcut keys (finishing version)

Source: Internet
Author: User
Tags string find

Most commonly used:

X Delete the following character x delete the previous character Delete 3 characters is 3x

DD: Delete one row D Delete to end of line

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 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

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.

Place the cursor at {, 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 "(").

%: Move to the bracket matching with the system up (),{},[],<> etc.

FX jumps right to the bank character X (x can be any character)

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. A total of 26 registers are available for you to record macros. With macros, you can repeat several different actions. 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.

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 line end 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, backward search in lowercase (used to locate) such as FX: Navigates to the next X. Fx: Navigates to the previous x, when repeated, available, or, however, represents the opposite direction

%: Jumps to the corresponding parentheses, commonly used in programming

33G: Jump To line 33 and press ' ' to return to the original line

GG: File header G: End of File

30%: Jump to 30% of files

"H" means home, "M" is Middle, "L" is last. The upper and lower position of the current screen, and the case can be

Ctrl+g: Show Current position

ctrl+u\d scroll up \ Down half screen

Ctrl+e\y scroll up \ down one line

ctrl+b\f scroll up \ Down a screen this is more practical, remember.

ZZ: Scrolls the current line in the middle of the screen for easy viewing context zt pinned, ZB tail

/string find String, enter, press the N key can jump to the next, N, and press the/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 #是查找上一个

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 ( command mode )

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 row D Delete to end of line

CAW: Rewrite the word c 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 also true: 10,20d (this method is simpler than the two methods above)

: 10,20 m 30 10 rows to 20 lines, cut to 30 rows

: 10,20 Co 30 10 rows to 20 rows, after copying to 30 lines

Place the cursor at {, 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 replaces a long string with an abbreviated 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. A total of 26 registers are available for you to record macros. With macros, you can repeat several different actions. 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 line end 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, backward search in lowercase (used to locate) such as FX: Navigates to the next X. Fx: Navigates to the previous x, when repeated, available, or, however, represents the opposite direction

%: Jumps to the corresponding parentheses, commonly used in programming

33G: Jump To line 33 and press ' ' to return to the original line

GG: File header G: End of File

30%: Jump to 30% of files

"H" means home, "M" is Middle, "L" is 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 a screen this is more practical, remember.

ZZ: Scrolls the current line in the middle of the screen for easy viewing context zt pinned, ZB tail

/string find String, enter, press the N key can jump to the next, N, and press the/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 highlighting Find results

: Set Nohlsearch Suppress highlighting

: Nohlsearch Remove the high end of the current display (one-time)

"Last cursor docked row

% matches to corresponding brackets

>> move the bank to the right for a distance << move the bank to the left for a distance 3<< the following 3 lines (including the bank), move 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 replaces str1 for each row as str2

: 10,20s/str1/str2/g replaces str1 from line 10 to line 20 as str2

: Ten, $s/str1/str2/g replace the str1 from line 10 to the last row is str2

: S/str1/str2/g replaces the current line str1 to str2

. Repeat command

: 10,$ w test2.cpp Row 10 to the last row, save to Test2.cpp

: R CLASS/USER.HPP reads the contents of the file and inserts it after the current line

DW: Delete a word (after the cursor part) inferior to: Daw utility 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 start of the 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 the cursor 3 p: Paste 3 times "2p paste last second deleted content

YY: Copy a line yaw: Copy a word, 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 ~/.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 and enter edit mode, equivalent to CC. NS: Delete the next n characters and enter edit mode.

~: Changes the case of the letter while the cursor enters the next character. n~: Change the case state of the back N letters.

DW: Delete word after section db: Delete Word before section. 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 the word, the 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 to do with 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: Search for X to the right in the bank and place the cursor 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) DTI to the right: same as DFI, except 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

Reference: http://www.cnblogs.com/tianyajuanke/archive/2012/04/25/2470002.html

VIM frequently used shortcut keys (finishing version)

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.