Vim Usage Tips

Source: Internet
Author: User
Tags save file

Vim is divided into command mode and edit mode. Press the ESC key to exit edit mode. all the following ' # ' numbers represent numbers.

One, move the cursor in command mode

#h the left #j #k上 #l right

0/^/home move to beginning $/end to end of line

W moves to the beginning of the next word, E moves to the next or end of the current word, B moves to the beginning of the previous or current word

w/b/e, like lowercase w/b/e, just use spaces as boundaries for word, and they can all work with #

The #fx looks in the current row to have a direction to find the # character X FX on the current line to the left to find the character X

T is the same as F, except that the cursor rests on the first character of the character being searched, and these four commands can be used ";" Or "," repeat

ZZ/ZT/ZB Place the current line in the center/top/bottom of the screen

ZZ saves the current file and exits vim

Here is the command to jump:

#G move to # line G to the last line GG moves to the first row can jump to the position before the jump with two open single quotes (that is, the inverted single quote "'")

% is moved to match one parenthesis, and the current cursor is not in parentheses, and a parenthesis is found forward. Same applies to} and]

#% that jumps to the file's percent # place

Ctrl+o jumps to the position where the cursor was stopped earlier ctrl+i jumps to the updated position where the cursor was later stopped

Ctrl+f forward screen ctrl+b back turn screen ctrl+d forward half screen ctrl+u back half screen

Ctrl+g tells you the line number of the current line of the cursor

Two, insert text or line

I insert a character before the cursor position I add text at the beginning of the current line A at the cursor position insert character A adds text at the end of the current line

R replaces the character at the cursor where the cursor is located, until ESC is pressed

J merge cursor line and next behavior line alt+j line wrap

o Insert a new line after the current line O insert a new line before the current line

Three, three ways to change the text

1, operator command + displacement command

D$/D Delete the position from the current cursor to the end of the line

D#w Delete from the current cursor to the beginning of the next # Word d#b Delete from the current cursor to the end of the previous word

DG deletes the contents of the current line to the end of the file DGG delete the contents of the current line to the header #dd Delete # lines

#x/#dl Delete the # characters to the left of the cursor #X/#dh Remove the # characters to the right of the cursor XP Exchange two-character position

y$/y copying characters from the beginning of the cursor to the end of a line

Y#w Copy the character from the beginning of the cursor to the end of Word # (Ye does not copy space after word) #yw

y^ copying characters from the beginning of the cursor to the beginning of the line

YY copies the cursor on the same line #yy

C is similar to D, but only after operation into insert mode

s represents CL, modifies a character s to represent CC, modifies a whole line

C$/C changes the current cursor to the end of the line

The above command has a fixed pattern: the operator Command + displacement command (used in conjunction with the command in the move cursor). If d4l deletes the current position of the cursor to the fourth character, where the displacement command includes both exclusive and inner packets, if the inner package (such as $) is shifted, the character of the cursor will be deleted.

2, Visual Mode

V Visual v Visualize line Ctrl + v. Visual Matrix

o Place the cursor over the other end of the selected text o when using a visual matrix, O moves the cursor between the left and right two corners of the same row

D Delete y copy

3, Operator command + text object

DIW delete the white space character after the current cursor is located in Word without removing the white space character Daw

Dis deletes the sentence in which the current cursor is located, excluding any subsequent whitespace characters

Where IW is is a text manipulation command, this form of command takes the entire text object, regardless of the current cursor position, as

The Action object.

#p paste #P The cursor before the cursor

D,x is used in conjunction with P to cut, which requires vim to support clipboard operations

u cancel operation u undo all operations on the current line ctrl+r recovery undo

Copy text under Windows, in the Vim of Linux, paste with Alt+shift+v

Four, replace

#r <Enter> Replace # characters for line breaks

R lets vim enter replace mode, and each typed character will replace the character under the current cursor until you type <Esc> end the pattern

You can switch back and forth between insert mode and replace mode with the <insert> key, and when you return with the <BS> key, the original character returns.

. The command that repeats the last change (except for the U Command ctrl+r and: The command that starts with, and does not include the move cursor)

For example, if four of the text is five, the executable command:/five<enter> cwfive<esc> N. N.

Delete the <*> in the text, and execute the command:f< df> f<. f<.

Five, command-line mode instructions

: E filename Edit file, you can press the <Tab> key to complete the filename, if you do not want to edit the file, continue to press <Tab>

Or use Ctrl+d to see the many complement candidate options

: q! Discard changes, Force exit

: w filename Saves the current file and modifies the file name to filename

: Nohlsearch removes the current highlight

: SaveAs move.c Save the current file as a new file Move.c file

Search and Replace commands:

/string search string, character. *[]^%/"$ has a special meaning and needs to be added in front of it. The "/" is generated by pressing a space.

The work is the same as/, but in the opposite direction.

You can also place the cursor over the string you want to search, and press the * or # key to search for the string, which can be used with numbers

/\<word\> find Word as a standalone word

/^word matches the beginning of a row word/word$ matches the end of a line word

/W.D matches any previous character when W, the latter character is the case of D. ”.” Represents any one character except for the line break

Common options Configuration

Set NU Display line number

Set Autoindent/cindent Auto Indent

Set TabStop the width of the TAB key

Set Ignorecase/noignorecase Ignore case/ignore case when searching

Set Hlsearch/nohlsearch highlighting/canceling highlighting

Set Backupext=.bark backup file, if the source file name is Data.txt, the backup file name is Data.txt.bark

Set autowrite settings Auto save file Set Noautowrite

Common displacement keys on the command line

Ctrl+b or home crtl+e or end

Ctrl+w the entire word before the cursor is deleted ctrl+u all the typed content before the cursor is deleted

Shift+<left> or ctrl+<left> One word to the left (not for all computers)

ctrl+c/<esc> Discard all commands that have been typed

The <insert> button toggles the insertion and rewriting of characters into two modes

Vim Usage Tips

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.