Common Vim commands

Source: Internet
Author: User

Vimm (vimsual) is a full-screen editor used in Linux/Unix OS.

Vimm is divided into two states: command status and edit status. In command status, the entered character system performs command processing. For example, Q indicates that the system exits, the editing status is used to edit text materials. When you enter vim, it first enters the command status. In the command status, press "I" (insert) or "A" (ADD) to enter the editing status. In the editing status, Press ESC to enter the command status.

In the command status, there are some common commands:

New:

A. Add text after the cursor

A. Add text from the end of the row where the cursor is located

Insert:

I insert text from front of the cursor

I insert text from the beginning of the row where the cursor is located

Delete and modify:

X Delete characters at the cursor

Dd deletes the entire row where the cursor is located.

3DD Delete the row where the cursor is located and the following two rows

D. Delete the text from the cursor to the end of the line. It is commonly used to delete the comment Statement (d $)

Move the cursor:

In remote logon mode, VIM does not support function keys such as Pageup, Pagedown, home, and end! (Depressing)

^ Move the cursor to the beginning of the line

$ Move the cursor to the end of the row

CTRL + D flip down half page

CTRL + F flip down one page

CTRL + u flip up half page

CTRL + B turn up one page

Gg move cursor to Document Header

G cursor to end of document

H. move the cursor to the current header.

L move the cursor to the beginning of the last row on the current page

W move one word behind the cursor

B. move the cursor one word forward.

[N] + the cursor moves n rows backward, and [N] indicates an integer.

[N]-move the cursor n rows forward, and [N] indicates an integer

[N] G cursor locates at the beginning of line N, [N] indicates an integer


Search and replace:

/[STR] search string STR, [STR] indicates the string to be searched

Press enter to highlight all the strings found.

Command n moves to the next string, and command n moves

The previous found string EG/Hello

Partially replace (only the row where the cursor is located can be replaced)

:S/[SRC]/[DST]/I ignore case sensitivity/g all match eg: S/Hello/World/ig replace one line

:3, 6 S/[SRC]/[DST]/ig (found in 3-6 rows) eg: 3, 6 S/Hello/World

Replace all

:% S/[SRC]/[DST]/g replace all SRC strings in the document with DST strings

:% S/^ // G remove the spaces at the beginning of each line of the document

Block operation:

V visual block selection status. After selecting a block, you can delete the block (D), copy (Y), and cut (X)

YY copy the entire line of the cursor

[N] YY copies n rows starting from the cursor. [N] indicates an integer.

P paste the copied text to the cursor

U undo the last operation

End Editing:

: Q: exit without modifying the document

: Q! Discard Document Modification and force exit

: W document storage

: WQ document disk exited

Others:

: HELP command to view the help prompt of this command

: %! Xxd hexadecimal Mode

: %! Xxd-r return text mode

If you accidentally press Ctrl + s during the editing process, VIM will be frozen and can be restored by pressing CTRL + q.

Run VIM + 3 main. C // to locate the 3rd line of Main. C.

Run VIM +/printf main. C // to locate the first printf.

In command mode, enter new2.c // to open a Vim file, and use vnew2.c to represent vertical lines.

You can also switch between two windows by using: Ctrl + W, W

Enter Gg = g in command mode to automatically align

Sed: Pipeline find replacement program

Cata.txt | SED's/AA/BB/'> B .txt // replace AAAS in a.txt with bbts and output them to B .txt.

: R my_open.c

Read my_open.c to the current directory.


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.