Vim Shortcut key Encyclopedia

Source: Internet
Author: User

Key word: Vim

Objective

Vim is a Super Cow editor, can be said to be designed for the programmer editor, powerful some incredible. But its learning curve slightly steep, the first two days on the internet to find a small chart, relatively full, if the table listed in the command learning familiar with the processing of daily text is enough, so posted, we refer to reference.

The place of Vim's cow B is not so varied as its function, more than the steep learning curve, but most of these commands can be combined, for example, 9yy command to copy 9 lines of content, 9 means to copy the number of rows, the same 100dd means to delete 100 lines, when the number and command cooperation, is more powerful than simple commands, similarly, the C command means erase, w means word is the word, then CW means erasing a word, c5w means to delete 5 words and so on. By composing these simple commands together, you can play a powerful and unimaginable function and make your editing work fun.

Macros Command (Macros)

Advanced Editor, will contain macro features, Vim is certainly not missing, in Vim, the use of macros is very convenient:

: QX

Start recording macros and save results to register X

Q

Exit record mode

@x

Play macro commands that are recorded in the X register

To give a little explanation, when you enter in normal mode: After QX, all your edits to the text will be recorded, re-enter Q to exit the recording mode, and then enter @x to repeat the command you just recorded, which can be followed by numbers, indicating how many times you want to repeat, such as @x20, You can repeat it 20 times. This is useful in batch processing of text.

Edit multiple files at the same time

In the vim many plug-ins, has a call Minibuffer plug-in, is the following said the tab page function, may support simultaneously edits several files.

Label command

: Tabe fn

Edit the file fn in a new tab page

Gt

Switch to next tab page

GT

Switch to previous label page

: Tabr

Switch to First label page

: tabl

Switch to the Last tab page

: TABM [N]

After the current tab is moved to the Nth tab

Yes, as you might imagine, a label page with Eclipse, UE, and so on, is a meaning.

Window command

Ctrl+w s

Horizontal split Window

Ctrl+w W

Toggle Window

CTRL+W Q

Exits the current window (this command does not affect other windows because there are multiple files at the same time)

Ctrl+w V

Vertical split Window

Other

Vim does not make actual modifications to the file until it is saved, but is loaded into the buffer, and edits to the file are actually edited to the buffer, until: W will be deposited into the physical file.

: E File

Load the file into a new buffer

: Bn

Jump to next buffer

: BD

Delete buffer (close file)

: SP FN

Split the window and load FN into a new window

Exit editor

: W

Write buffer to file, save modify

: Wq

Save changes and exit

: X

Save changes and exit

: Q

Exit, if the buffer has been modified, you will be prompted

: q!

Force exit, Discard changes

Find replacement

/pattern

Search backwards for string pattern

? pattern

Forward search string pattern

N

Next match (if yes/search, then next down,? Search is next up)

N

Previous match (IBID.)

:%s/old/new/g

Search the entire file and replace all old with new

:%S/OLD/NEW/GC

Search the entire file, replace all old with new, and each time you confirm whether to replace

Copy and paste

Dd

Delete the cursor in the row

Dw

Delete a word (word)

X

Delete current character

X

Delete previous character

D

Delete to end of line

Yy

Copy a row, which can be followed by a number, identifying multiple rows, such as 6YY, that replicate 6 rows from the current line

yw

Copy a Word

y$

Copy to end of line

P

Paste the contents of the pasteboard below the current line

P

Paste the contents of the pasteboard onto the top of the current line

]p

With indented paste, Vim automatically adjusts the indentation of the Code

"A

Put the content into/into a register, you can support multiple paste board

Attached: For example, a commonly used register is the system register, the name is +, so paste from the system paste into the vim in the command for "+p, note here the + does not represent the operator, 21 registers."

Move cursor

Moving the cursor in VIM is a big difference from other editors, but once you learn it, you can move through the text quickly.

H,j,k,l

Up, down, left, right

Ctrl-f

Turn up a page

Ctrl-b

Next Turn page

%

Jumps to the parentheses that match the current bracket, such as currently in {, and jumps to the place where it matches

W

Skip to the next word and divide by punctuation or word

W

Jump to the next word, long jump, such as end-of-line is considered a word

E

Skip to the end of the next word

E

Jump to the end of the next word, long jump

B

Skip to previous word

B

Jump to the previous word, long jump

0

Jump to the beginning of the line, whether or not indented, or skip to the No. 0 character

^

Jumps to the first character at the beginning of a line

$

Skip to end of line

Gg

Jump to the first line of a file

Gd

Jumps to the declaration of the variable where the current cursor is located

N G

Jump to Nth line, such as 0G, is equivalent to gg,100g is the 100th line

Fx

Find the X character in the current line and jump to

;

Repeat the previous F command without having to repeat the input FX

Tx

Similar to FX, but only jumps to the previous character of X

Fx

Contrary to the FX direction.

),(

Jump to the top/Next statement

*

Find the word at the cursor and look down

#

Find the word at the cursor and look up

`.

Jump to last edit location

Moving on the screen

H

Move the cursor to the topmost line on the current screen

M

Move the cursor to a row in the middle of the current screen

L

Move the cursor to the bottom line on the current screen

Bookmark

Ma

Save the current position as a label a

' A

Jump to label A

Edit

R

Replace one character

J

Connect the next and current rows to one line

Cc

Deletes the current line and enters edit mode

cw

Deletes the current word and enters edit mode

C $

Erase content from current position to end of line and enter edit mode

S

Deletes the current character and enters edit mode

S

Delete the line where the cursor is located and enter edit mode

Xp

Swap the current character and the next character

U

Revoke

Ctrl+r

Redo

.

Repeat previous Edit command

~

Toggle case, current character

G~iw

Toggles the case of the current word

Guiw

Turn the current word into uppercase

Guiw

Turn the current word to lowercase

>>

Move the current line to the right one unit

<<

Moves the current line one unit to the left (a tab character)

==

Auto Indent when forward

Insert mode

I

Enter insert mode from current cursor

I

Enter insert mode and place the cursor at the beginning of the line

A

Append mode, placing the cursor after the current cursor

A

Append mode, placing cursor at end of line

O

Add a new row below the current line and enter insert mode

O

Adds a new row above the current line and enters insert mode

Esc

Exit Insert Mode

Visual mode

Tagged text

V

Enter visual mode, single character mode

V

Enter visual mode, row mode

CTRL + V

Enter visual mode, column mode, similar to UE column mode

O

Jump cursor to another endpoint of the selected block

U

Turn the contents of the selected block into uppercase

O

Jump cursor to another endpoint of a block

Aw

Select a word

Ab

Check everything in parentheses, including the parentheses themselves

Ab

Select all contents of the {} brackets

Ib

Select the contents of parentheses without parentheses

Ib

Select content in {}, excluding {}

To act on a marker

>

Move the block to the right

<

Block Move left

Y

Copy Block

D

Delete Block

~

Toggle the case of content in a block

Well, here's the short list, of course it covers a limited range, but as the title says, Vim's strength is that these commands can be combined and used to reflect its powerful editing capabilities. I found this document on the Internet also by the way posted, you can refer to the same time. If there is a chance, I try to find some examples to illustrate the use of these commands in practice, so that it can be used better, improve our efficiency.

A summary of the replacement patterns commonly used in vim.


1, simple substitution expression

The substitution command can replace another word with one word in the full text:

:%s/four/4/g


The "%" range prefix indicates that replacements are performed in all rows. The last "G" tag represents all the matching points in the replacement row. If you are only working on the current line, you can simply remove the%

If you have a word like "thirtyfour", the above command will go wrong. In this case, the word will be replaced with "Thirty4″." To resolve this problem, use "\<" to specify the beginning of the matching word:

:%s/\<four/4/g

Obviously, this will make a mistake when dealing with "fourty". Use "\>" to solve this problem:

:%s/\<four\>/4/g

If you are coding, you may only want to replace the "four" in the annotation and keep the code in the. Because this is difficult to specify, you can add a "C" tag to the substitution command so that Vim prompts you before each replacement:

:%S/\&LT;FOUR\&GT;/4/GC

2, remove the extra space

To remove the extra space after each line, you can execute the following command:

:%s/\s\+$//

The command indicates that the range is "%", so this will work on the entire file. The match pattern for the "substitute" command is

"\s\+$". This represents one or more (\+) spaces (\s) before the end of the line ($). The "to" section of the substitution command is empty: "//". This will delete those matching whitespace characters.

3, matching the pattern of repetition

The asterisk entry "*" stipulates that the item in front of it can be repeated any time. So:

/a*

Match "A", "AA", "AAA", and so on. But also matches "" (empty string), because 0 times also contains. The asterisk "*" applies only to the item immediately preceding it. So "ab*" matches "a", "AB", "ABB", "abbb", and so on. To repeat the entire string multiple times, the string must be composed of an item. The way to make an item is to precede it with "\ (", followed by "\)". So this command:

/\ (ab\) *

Match: "AB", "Abab", "Ababab", and so on. and also matches "".

To avoid matching empty strings, use "\+". This means that the previous item can be matched one or more times.

/ab\+

Match "AB", "ABB", "abbb", and so on. It does not match "a" followed by "B".

To match an optional option, use "\=". For example:

/folders\=

Match "folder" and "Folders".

4, specify the number of repetitions

To match a specific number of occurrences of an item, use a form such as "\{n,m}". where "n" and "M" are numbers. The item in front of it will be repeated "n" to "M" Times (|inclusive| contains "n" and "M"). For example:

/ab\{3,5}

Match "abbb", "abbbb" and "abbbbb".

When "n" is omitted, the default is zero. When "M" is omitted, the default is infinity. When ", M" is omitted, it means repeating exactly "n" Times. For example:

Pattern matching times

\{,4} 0,

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.