Vim Commands--Quick start, walk the lake

Source: Internet
Author: User

Vim has a lot of detailed commands, we use a number of common entry commands, enough to deal with the daily code editing work, if you need to use other commands later, it is not too late to query.

Vim generally has 3 editing modes, namely insert mode, Normal mode, and last line mode.

The following is mainly in normal mode operation, other mode operation will indicate the relevant mode

1.1 moving the cursor

H------> Press Left to move each time

J------> Move Down every time you press

K------> Move up each time you press

L------> move to the right each time you press

1.2 Vim's entry and exit

Press the <Esc> key to enter normal mode

Then enter the following several ways to exit

: Q  # do not save and exit Vim: q!    # Force exit : Wq  # Save the file and exit : x    # equals: Wq                 

1.3 Deletion of text edits

Under normal mode, you can press the X key to delete the character at the cursor location.

1.4 Insertion of text editing

There are several ways to enter insert mode in normal mode:

You can press the I key to insert text at the cursor.

Press the A key to insert text after the cursor.

Press the capital A key to insert text specifier the last word in the line where the cursor is located.

1.5 Adding text edits

Press the A key to add the text at the end of the line where the cursor is located

Press the A key to add after the cursor position

2.1 Delete class commands

The input DW can be removed from the cursor at the end of a word.

2.2 About commands and objects

Many commands that change text consist of an operator and an action.

The deletion command using the delete operator D is in the following format:

D Motion

which

D-delete operator

Action object for the motion-operator (listed below).

A short list of actions:

W-from the current cursor position to the beginning of the next word, excluding its first character.

e-from the current cursor position until the end of the word, including the last character.

$-from the current cursor position until the end of the current line.

2.3 Using a count to develop an action

Entering the number n before the action causes it to repeat n times.

Enter 2w to move the cursor backwards by 2 words.

Enter 3e to move the cursor backwards to the end of the 3rd word.

Enter 0 (number 0) to move the cursor to the beginning of the line.

2.4 Use Count to remove more

Enter the number n when using the operator, and you can make it repeat n times.

Example: Operation number (digital) motion

d2w can delete 2 words.

2.5 manipulating entire rows

The input DD can delete a current line and save it to a register, acting like a "cut" operation, which can be used with the P operation.

2.6 Undo Class Command

Enter u to undo the last executed command, and enter U to undo the modification of the entire row.

With Ctrl + R, you can undo a previous Undo command.

3.1 Placing class commands

Enter p to place the last cut content after the cursor.

3.2 Replace class command

Move the cursor to the character position you want to modify, enter R and a character to replace the character where the cursor is located.

3.3 Changing the class command (C command, meaning "change")

To change the text until the end of a word, enter CE.

3.4 Use C to change more

c [NUMBER] Motion

Motion parameters motion is the same, it can be W, E, $d.

4.1 Positioning and file status

Enter Ctrl + G to display the line position of the current cursor in the current edit file and the file status information.

Enter uppercase G to jump directly to the last line of the file.

Enter Ng, and you can jump to the row with the line number N.

Enter GG and you can jump to the first line of the file.

4.2 Search class commands

Enter/Add a string to find the string in the current file. To find the next string, press the N key, if you want to reverse the lookup, enter uppercase N.

If you want to reverse search, type? Replace/.

4.3 matching parentheses for lookup

Position the cursor in the bracket to be paired, enter% to find another pair of parentheses),],}.

4.4 Replace Command

Input: S/old/new, you can replace the string at the old line at the same time as the string at new.

Input: s/old/new/g, which can replace the string at all old of the line with the new.

Enter: #, #s/old/new/g, where #,# represents the line number of the start and end lines of the replacement operation.

Input:%s/old/new/g is the replacement of each matching string in the entire file.

Input:%S/OLD/NEW/GC, each matching string in the entire file is found, and the hint is replaced for each matching string.

5.1 Methods for executing external commands within VIM

Input:! The external command can then be executed immediately after entering an external command.

For example,:!ls + ENTER, which is the listing of the contents of your current directory.

5.2 More information about saving files

To save changes to a file, enter: W file name.

5.3 A Selective Save command

You can save the selected content to the destination file by pressing the V key to select a portion of the file to save and then entering: W file name.

5.4 Extracting and merging files

To insert the contents of another file into the current file, enter: R file name.

6.1 Open Class command

Enter o to open a new line below the cursor and into insert mode.

Enter capital O, which opens a new line above the cursor and enters insert mode.

6.2 version of another permutation class command

Enter an uppercase R to replace multiple characters consecutively.

6.3 Copy and paste text

Use operator y to copy text and paste with P.

Enter YY to copy the line where the cursor is located.

Can be used with motion parameters motion:

Enter YW to copy a word.

Vim Commands--Quick start, walk the lake

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.