Linux vim common shortcut keys __linux

Source: Internet
Author: User
Tags add numbers file copy string find

1, vim ~/.VIMRC into the configuration file

If you don't know where the VIMRC file is, you can use: Scriptnames to view

Set Nu #行号

Set tabstop=4 #一个tab为4个空格长度

Set AI #设置自动缩进

Syntax on #高亮

2, basic

Space bar to move one grid to the right

x Delete after character x delete the previous character Delete 3 characters is 3x

DD: Delete line D Delete to end of line

CAW: Rewrite word c equivalent to D into edit mode

J: Delete line breaks to make the next line come up. NJ: N lines behind the connection

U: Undo Last Action U: Undo all changes to current line

Ctrl+r: Undo Undo

I insert before the cursor

I Insert at the beginning of the line
A after the cursor inserts

A at the end of the insertion

O: Another line below the current line and becomes insert mode

O: Another line above the current line, into insert mode

Ctrl+o: Temporarily into command mode (just once)

: e!: Discard changes, and then turn the equivalent back on

: Help: Helps, use ZZ to exit Help window

In Vim, Nyy can copy n rows after the cursor. Sometimes it's not easy to get the number of trips that can be used as a marker to make the replication range:

1. Enter Ma as a marker on the start line

2. Move to the end line, and entering Y ' a duplicates the text between the current line and the tag a. d ' A will be deleted.

or V into the visual mode, and then 13G jump to the corresponding line, Y can.

: 10,20y carriage return, the corresponding deletion is the same: 10,20d (this method is simpler than the above two methods)

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

: 10,20 Co 30, 10 lines to 20 lines of content, copied to 30 rows after

Place the cursor in {, 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 the input dt (OK, t (the function is to skip to the next "(").

CTRL +n Auto-fill CTRL + P Also

: AB HW Hello World replaces a long string with an abbreviated string, with HW instead of Hello World

%: Move to matching brackets up (),{},[],<>

' Move to the last modified row

FX jumps to the right of the bank character X (x can be any character)
Fx jumps to the left of line character X (x can be any character)
TX and FX are the same, the difference is to jump to the character x before
Tx and FX are the same, and the difference is to jump to the character x to the same word 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 register variable a '.
Press down and you can type what you want to do as usual, but these operations will be recorded by Vim in the macro named A, and then the "Q" key, which ends the recording of the macro ' a '. Just use the "@a" command when you want to repeat the actions you just recorded. A total of 26 registers are available for you to record macros. You can use macros to repeat a number of different actions. Instead of just inserting text. If you're going 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 automatically replaced with the following.

3. Move:

B, 3b, W, 3w: Move forward \ After 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 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 for commands, lower case search backwards (for positioning) such as FX: Navigate to the next X. Fx: Positioned to the previous x, when repeated, available, or, however, represents the opposite direction

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

33G: Jump to 33 line now press "to return to the original line

GG: File head G: End of File

30%: Jump to 30% of the file

"H" means home, "M" is Middle, "L" is last. The upper and lower position of the current screen, both uppercase and lowercase

Ctrl+g: Show Current position

Set Number: Sets display line numbers, set Nonumber: Off display

: Set ruler to display line numbers in the lower-right corner of the window, with the benefit of saving space

Ctrl+u\d up \ Bottom scrolling half screen

Ctrl+e\y scroll up \ down one line

ctrl+b\f up \ Scroll down a screen this is more practical, remember.

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

/string find String, enter, press n key to jump to the next, N prev, press/key, press the up and down key can find the previous lookup records, the same: there are records

?/string ditto, default up lookup

: Set ignorecase case Independent

: Set noignorecase case sensitive: Find the next word in the cursor #是查找上一个

: Set Hlsearch Highlight Find results

: Set Nohlsearch suppresses highlighting

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

The line where the last cursor was docked

% match to appropriate brackets

Move the line to the right for a distance << move the line to the left for a distance 3<< 3 lines (including the bank) to the left to move a distance:20,30>> 20 lines to 30 to the right for a distance

4. Minor changes:

:%s/str1/str2/g replaces str1 for each row with str2

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

: $s/str1/str2/g replaces str1 between line 10 and last line as str2

: S/str1/str2/g replaces the str1 for the current line as str2

. Repeatedly execute command

: 10,$ W Test2.cpp take 10 to the last line of content, save to Test2.cpp

: R CLASS/USER.HPP Read the contents of the file and insert it behind the current line

DW: Delete a word (after the cursor): 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 start D change to C effect is the same, only after the operation will become insert mode DNW: delete n words dnj: to Delete N line dnk: delete up n rows

X: Delete the left character, equivalent to the <-key, x delete the current character D: the equivalent of D C: equivalent to C: the equivalent of C 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 R: Replace mode

.: Repeat Last Action

V: Enter visual Mode V: Enter visual line mode, such as VJJD delete 3 lines Ctrl + V: Visual block mode

P: Paste to Cursor P: Paste to Cursor after 3 p: Paste 3 times "2p Paste last second delete content

YY: Copy a line yaw: Copy a word, the cursor at any position in the word ynw: copy n words ynj: Copy down n rows ynk: Copy up n rows

Auto indent:

: Set Cindent (all set can be abbreviated to SE, although only one character is saved, the translator Note) Note that the Cindent control indent is through the Shiftwidth option value, not the TabStop value, and the Shiftwidth default value is 8 ( In other words, one indentation is 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 a indent amount to represent.

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

5, some of Vim's plug-ins:

C.vim: If it is with root account, the file copy to/usr/share/vim/vim70 decompression is not used, there is no $HOME/.vim This directory, there is no way, can only create a new directory, and then the compression of the 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 at the beginning of the line, the cursor is at the beginning of the line, 0 back to the beginning, and the cursor is before the beginning. $ back to the end of the line, the cursor is at the end of the letter.

NB: move n words forward, NW: move n words backwards. The cursor is at the first letter of the word. NW This operation is slow, somehow. Delimiters are delimited by spaces, punctuation marks, and word boundaries. (Several consecutive punctuation is treated as a single word)

Similarly, you can use NB,NW, except that you use a space as a separator.

Change the position of two adjacent letters: x, p

S: Deletes a character and enters edit mode. S: Deletes an entire line and enters edit mode, equivalent to CC. NS: Deletes the following n characters and enters edit mode.

~: Change the case of the letter, while the cursor goes to the next character. n~: Changes the case state of the following n letters.

DW: Remove the back part of the word DB: Delete the previous section 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 remove the space after the word) DE: The range of deletion includes the end of the word, including the label.

E: The equivalent of W, move one word backwards. The difference is that W moves to the first character of the word, and e moves to the last character of the word. So EA, you can add content to this word.

D:d shorthand, same, c:c shorthand, same, c:c shorthand.

U: Will restore a whole line of the original appearance, that is, the original appearance.

Y: The equivalent of YY, different from D and C operation methods.

.: Repeat 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: Merge the following n lines (from the bank).

YNL: Copy n characters backwards.

E/E: To the end of the word.

Scrolling whole screen:

^f: Forward (down) an entire screen

^b: Back (UP) an entire screen

^d: Forward (next) Half screen

^u: Back (up) half screen

Z,enter: Move the line of the cursor to the top of the screen (same as ZZ)

Z.: Move the line of the cursor to the middle of the screen

Z: Moves the line at the cursor to the end of the screen

Nz,enter: Move the nth line to the top of the screen, and the same, Z. With the Z-front can also add numbers.

To move through the screen:

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

NH, NL move to the position of the top and top n rows of the screen.

Enter: To the first character on the next line.

+: The first character to the next line.

-: To the first character on the previous line.

n|: Move to nth column of current row

E: Move to the end of a word

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

() {} [[]] These few programming functions are insignificant and can be ignored.

D/it: Remove backward to the location before it (without deleting it). D?it: Move forward to where it was before it (remove it).

FX: the line is searched to the right x and the cursor is placed on X. Fx: Search to the left.; Repeats the previous search command in the same direction. , repeat the previous Search command, in the opposite direction.

TX: With FX, only the cursor is placed before X. Tx similar.

DFI: Delete the position of the first I in the right (including i) DTI: with DFI, just not including I

Ctrl+g View Current line information

After Ng jumps, you can use the "go back to last position," function, but just go back to the beginning of the line where the previous position is, not the position you identified.

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

Delete blank line::%s/^\n$//g

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.