Common VIM commands-Quick Start, Jianghu, and vim commands

Source: Internet
Author: User

Common VIM commands-Quick Start, Jianghu, and vim commands

There are many detailed VIM commands. We use some frequently used entry commands to deal with routine code editing. If you need other commands in the future, it is not too late to query them.

Vim generally has three editing modes: insert mode, normal mode, and last line mode.

The following operations are mainly performed in normal mode. operations in other modes indicate the relevant modes.

 

1.1 move the cursor

H ------> move each press to the left

J ------> move down every time you press

K ------> move up every time you press

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

 

1.2 enter and exit vim

Press <Esc> to enter normal mode.

Then, enter the following methods to exit.

: Q # Do not save and exit vim: q! # Force Exit: wq # Save the file and exit: x # equivalent to: wq

 

1.3 Delete text editing

In Normal mode, press the x key to delete the characters at the cursor position.

 

1.4 text editing insert

To enter the insert mode in normal mode, you can use the following methods:

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

Press key a to insert text behind the cursor.

Press the uppercase A key to insert text after the last character of the row where the cursor is located.

 

1.5 Add a text editor

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

Press the key and add

 

2.1 Delete class commands

Input dw can be deleted from the cursor to the end of a word.

 

2.2 about commands and objects

Many commands that change text are composed of an operator and an action.

The format of the DELETE command using the delete Operator d is as follows:

D motion

Where:

D-delete Operator

The operation object of the motion-operator (listed below ).

A brief action list:

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

E-from the current cursor position to the end of the word, including the last character.

$-From the current cursor position until the end of the current row.

 

2.3 define actions using counts

Input the number n before the action to repeat it n times.

Enter 2 w to move the cursor two words backward.

Enter 3e to move the cursor backward to the end of 3rd words.

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

 

2.4 use count to delete more

Input the number n when using the operator to repeat it n times.

For example, operation number (number) motion

D2w can delete 2 words.

 

2.5 operate the entire row

Enter dd to delete the current row and save it to the register. This operation is similar to the cut operation and can be used with the p operation.

 

2.6 undo class commands

Enter u to undo the last command, and enter U to undo the modification to the whole line.

Use Ctrl + r to undo the previous undo command.

 

3.1 placement commands

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

 

3.2 replace Class commands

Move the cursor to the character location to be modified, enter r and a character to replace the character at the cursor location.

 

3.3 change a class command (c command, that is, "change)

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

 

3.4 use c to change more

C [number] motion

The same is true for motion parameters w, e, and $ d.

 

4.1 positioning and file status

Enter Ctrl + g to display the row position and file status information of the current cursor in the current editing file.

Enter uppercase G, and then jump to the last line of the file.

Enter nG to jump to the row whose row number is n.

Enter gg to jump to the first line of the file.

 

4.2 search commands

Enter/Add a string to search for the string in the current file. To search for the Next string, press the n key. For reverse search, enter N in upper case.

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

 

4.3 search for matching brackets

Position the cursor at a bracket to be paired. Enter % to find another bracket to be matched.),],}.

 

4.4 replace command

Input: s/old/new. You can replace the string at the old of the row with the string at the new.

Input: s/old/new/g. You can replace all the old strings in the row with the new strings.

Input: #, # s/old/new/g, where #, # indicates the starting and ending rows of the replace operation.

Enter % s/old/new/g to replace each matching string in the entire file.

Enter % s/old/new/gc to find each matching string in the entire file and prompt whether to replace each matching string.

 

5.1 Method for executing external commands in VIM

Enter :! Then, enter an external command to execute the command.

For example ,:! Ls + press Enter. This command lists the contents of your current directory.

 

5.2 more information about saving files

To save changes to the file, enter the w file name.

 

5.3 a selective saving command

Press v to select the part of the file to be saved, and enter w file name to save the selected content to the target file.

 

5.4 extract and merge files

To insert the content of another file into the current file, enter the r file name.

 

6.1 open a class command

Input o. A new line is opened under the cursor and the insert mode is entered.

Input uppercase O. A new line is opened above the cursor and the insert mode is entered.

 

6.2 version of another replacement command

Enter an upper-case R to replace multiple consecutive characters.

 

6.3 copy and paste text

Copy text with the operator y and paste text with p.

Enter yy to copy the row where the cursor is located.

It can be used with the motion parameter:

Input yw to copy a word.

 

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.