Vim shortcut keys and vim common shortcut keys

Source: Internet
Author: User
Tags add numbers

Vim shortcut keys and vim common shortcut keys

1. vim ~ /. Vimrc enter the configuration file

If you do not know where the vimrc file is, you can use scriptnames to view it.

Set nu # row number

Set tabstop = 4 # A tab has four spaces.

Set ai # set automatic indent

Syntax on # Highlight

 

2. Basic

Move the Space key to the right

X Delete the following character X Delete the first character delete 3 character is 3x

Dd: delete a row D to the end of the row

Caw: rewrite the word c is equivalent to converting d into the editing mode.

J: Delete the linefeed to bring the next line up. NJ: n rows after the connection

U: undo the last operation U: undo all modifications of the current row

Ctrl + r: undo

I insert before the cursor

I insert at the beginning of a row
Insert a behind the cursor

A Insert at the end of A row

O: Start another row under the current row and change to the insert mode.

O: Start another row on the current row and change to the insert mode.

Ctrl + o: temporarily changed to command mode (only once)

: E! : Abandon the change, and then re-open it.

: Help. Use ZZ to exit the help window.

In vim, Nyy can copy N rows after the cursor. Sometimes we cannot easily get the number of trips. In this case, we can use the marking method to define the replication scope:

1. Enter ma on the start line to mark

2. Move to the end line and enter y' a to copy the text between the current row and Mark. D' a will be deleted.

Or v enters the visual mode, and then 13 Gb jumps to the corresponding line, y.

: 10, 20y, and press Enter. The corresponding deletion is also true: 10, 20d (this method is simpler than the above two methods)

: 10, 20 m 30 cut the content of 10 to 20 rows to 30 rows

: Co 30: copy the content of 10 to 20 rows to 30 rows

Place the cursor at {and enter v % to select the content in braces.

If the cursor is placed on the first s and you want to delete it until (), enter dt (that is, t (to jump to the next.

Ctrl + n auto-completion ctrl + p is the same

: AB hw hello world replaces a long string with an abbreviated string. hw is used to replace hello world.

%: Move to the matching brackets (), {}, [], <>, etc.

'Move to the last modified row

Fx jumps to x of the row to the right (x can be any character)
Fx jumps left to x (x can be any character)
Tx and fx are the same. The difference is to jump to the character before x.
Tx and Fx are the same. The difference is that

# To the last word that is the same as the current word, * to the next word that is the same as the current word

There is also a quick way to repeat a phrase or sentence. Vim has a macro recording mechanism. Enter "qa" to input a macro into register variable 'A.
Press down and you can enter the operations you want as usual, but these operations will be recorded by Vim into the macro named 'A', and then press the "q" key again, the recording of macro 'A' is finished. When you want to repeat the operations you just recorded, you only need to use the "@ a" command. There are 26 available registers for you to record macros. You can use macros to repeat multiple different operations. Instead of just inserting text. If you want to perform some repeated operations, remember to use this trick.

: Abbr hte

: Abbr hw Hello World

When you enter the first word, it is automatically replaced with the latter.

 

3. Mobile:

B, 3b, w, and 3 w: move a few words forward and backward. punctuation is also a word. The corresponding uppercase state is without punctuation, that is, only the space and linefeed are used as word separators.

$: Move to the end of a row 3 $: Move to the end of a row 3

^: Move to the beginning of the line. 0 is also

+: Move to the beginning of the next row

-: Move to the beginning of the previous row

F: SEARCH Command. Search backward (used to locate) in lower case, for example, fx: locate to the next x. Fx: Located on the previous x, available when repeated; or, however, indicates the opposite direction

%: Jump to the corresponding brackets. It is often used for programming.

33G: Jump to 33 rows. Then press ''to return to the original row.

Gg: File Header G: End of the file

30%: Jump to 30% of the file

"H" indicates Home, "M" indicates Middle, and "L" indicates Last. The upper and lower positions of the current screen, which are case sensitive.

Ctrl + G: displays the current location

Set number: set the display row number. set nonumber: Disable display.

: Set rsequence to display the row number in the lower-right corner of the window. The advantage of setting rsequence is that it saves space.

Ctrl + u \ d scroll up/down half screen

Ctrl + e \ y scroll up/down

Ctrl + B \ f scroll up/down this is more practical, remember.

Zz: Scroll the current row in the middle of the screen to make it easy to view the top position of the context zt and the end of zb.

/String: Search for the string. After you press enter, you can press the n key to jump to the next one. After you press the/key, you can press the up or down key to find the previously searched record. Similarly: there are also records

? /String is the same as above, which is searched up by default.

: Set ignorecase case-insensitive

: Set noignorecase case sensitive

*: Find the word where the next cursor is located # search for the previous one

: Set hlsearch highlight search results

: Set nohlsearch cancel highlighting

: Nohlsearch remove the currently displayed high-end (one-time)

'''Line of last cursor stop

% Matched to the corresponding brackets

> Move the row to the right for a distance <3 for moving the row to the left <3 for moving the following three rows (including the row) to the left: 20, 30> move 20 rows to 30 rows to the right.

 

4. Minor changes:

: % S/str1/str2/g replace str1 of each row with str2

: S/str1/str2/g replace str1 from line 10 to line 20 as str2

: 10, $ s/str1/str2/g replace str1 from row 10 to the last row as str2

: S/str1/str2/g replace str1 of the current row with str2

. Repeat the command

: 10, $ w test2.cpp fetch the content from the row 10 to the last row and save it to test2.cpp.

: R class/User. hpp reads the content in the file and inserts it to the end of the current row.

Dw: delete a word (the part after the cursor) not as good as: daw practical d4w: delete 4 words d $: Delete the current cursor to the end of the line d ^: deleting the current cursor to the beginning of the line d to c is the same effect, but the operation will become insert mode dnw: delete N words dnj: delete n rows down dnk: delete n rows up

X: Delete the character on the left, which is equivalent to <-key. x deletes the current character D: equivalent to d $ C: equivalent to c $ s: equivalent to c1 S: equivalent to cc

R: Replace the current character, but it does not enter insert mode 3r: Replace the last three characters with R: replace Mode

.: Repeat the previous operation

V: Enter Visual mode V: Enter the Visual line mode, for example, Vjjd deletes three rows Ctrl + v: The Visual Block Mode

P: paste before the cursor p: paste after the cursor 3 P: paste 3 times "2 p paste the last second deleted content

Yy: copy a row of yaw: copy a word. The cursor is at any position of the word. ynw: Copy N words. ynj: Copy n rows down. ynk: Copy n rows up.

Automatic indent:

: Set cindent (all sets can be abbreviated as se, although only one character is saved, note by the translator) Note that cindent controls the indentation by using the value of the shiftwidth option, instead of using the tabstop value, the shiftwidth default value is 8 (that is, an indent is 8 spaces, the Translator's note). To change the default setting, you can use ": set shiftwidth = x "command. x indicates the number of spaces that you want an indent to represent.

{= To the previous empty line
} = To the next blank line

 

5. Some VIM plug-ins:

C. vim: If the root account is used, it is useless to copy the file to/usr/share/vim/vim70, and $ HOME/does not exist /. there is no way to create the vim directory. You can only create a directory, then cp the compressed package to this directory, and then unzip it. In ~ /. Write filetype plugin on in vimrc

 

: E! Returns the last saved status.

Ctrl + z: Pause vi, return to the Unix prompt, and enter fg to return to vi.

^ Return to the beginning of the line, the cursor is at the beginning of the line; 0 returns to the beginning of the line, and the cursor is before the first letter of the line. $ Return to the end of the row, and the cursor is at the end of the row.

Nb: Move n words forward, and nw: Move n words backward. The cursor is at the first letter of the word. The operation in nw is very slow, somehow. It is separated by spaces, punctuation marks, and words. (Several consecutive punctuations are considered as one word)

Likewise, you can use nB and nW, But here only space is used as the separator.

Change the positions of two adjacent letters: x and p.

S: delete a character and enter the editing mode. S: deletes a whole row and enters the editing mode, which is equivalent to cc. Ns: Delete the next n characters and enter the editing mode.

~ : Change the case sensitivity of the letter and move the cursor to the next character. N ~ : Change the uppercase and lowercase letters of the last n letters.

Dw: Delete the db behind a word: Delete the front part of a word. If you want to delete the entire word (the cursor is in the middle of the word), you can use dbw \ wdb

De: similar to dw, delete the part after a word (delete only to the end of the word, dw will delete the space behind the word) dE: delete the end of a word in the range including the number.

E: w. Move a word backward. The difference is that w is moved to the first character of the word, and e is moved to the last character of the word. Therefore, ea can append content to this word.

D: d $ is short for C: c $.

U: restores the original appearance of a line, that is, the original appearance.

Y: equivalent to yy, different from the operation methods of D and C.

.: Repeat the previous command.

In addition to O/o, the INSERT command (A, a, I, I) accepts numeric parameters, such as 5 Ihello, and then press the ESE key. Enter five connected hello records at the beginning of the row.

Nr: Replace the next n characters.

NJ: Merge the following n rows (from this row ).

Ynl: Copy n characters backward.

E/E: to the end of a word.

 

Scroll the whole screen:

^ F: a whole screen forward (down)

^ B: a whole screen (up)

^ D: Front (bottom) half screen

^ U: half screen (up)

Z, Enter: Move the row where the cursor is located to the top of the screen (equivalent to zz)

Z.: Move the row where the cursor is located to the center of the screen

Z-: Move the row where the cursor is located to the end of the screen

Nz, Enter: Move row n to the top of the screen. Similarly, you can add numbers before z. and z.

 

Move on screen:

H, M, and L move to the top, middle, and end of the screen respectively.

NH and nL move to n rows from the top and top of the screen.

 

Enter: the first character in the next line.

+: The first character in the next line.

-: The first character in the previous line.

N |: column n to the current row

E: Move to the end of a word

E: Move to the end of a word (ignore punctuation)

() {} [[] Is not very useful for programming and can be ignored.

D/it: Delete the location before it (do not delete it ). D? It: the location before it is deleted (delete it ).

 

Fx: Search for x to the right of the row, and place the cursor over 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, except that the cursor is placed before x. Tx is similar.

Dfi: the position (including I) of the First I to the right to be deleted by the user.

Ctrl + G to view the current row Information

After nG jump, you can use ''to return to the previous position.'' has the same function, but only returns to the beginning of the row where the previous position is located, rather than the specified position.

 

Delete the row containing the keyword string: g/keyword/d

Delete empty rows: % s/^ \ n $/g

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.