Common vi/vim commands and common vivim commands

Source: Internet
Author: User

Common vi/vim commands and common vivim commands
Working Mode


INSERT command

A attaches text behind the cursor

A adds text at the end of the line

I insert before the cursor

I insert text at the beginning of the line

O Insert a new row under the cursor

O Insert a new line to the cursor

Locating command

H move one character to the left/the arrow to the left

J. Move down one row/down arrow

K move up one row/Up Arrow

L move one character to the right/the arrow to the right

$ Move to the end of a row

0 (number zero) Move to the beginning of the line

H move to the top of the screen

M moves to the center of the screen

L move to the bottom of the screen

Ctrl + f flip down one page forward

Ctrl + B flip one page forward backward

Ctrl + d flip half page down

Ctrl + u up half page forward

Quick Positioning

: Set nu display row number

: Set nonu cancel row number

Move gg to the first line

Move G to the last row

NG to n

: N to row n

DELETE command

X: Delete the cursor character

Nx deletes n consecutive and backward characters

Dd deletes the row where the cursor is located and ndd deletes n rows.

DG deletes all rows from the current row to the end of the file, including the current row

D. Delete the content from the cursor position to the end of the line.

: N1, n2d Delete n1 ~ N2 row


Copy command

Yy and Y copy the current row

Nyy, nY copy n rows

Dd: Cut the current row. ndd: Cut the current row and the next n rows.

P paste under the current row

P [uppercase] pasted on the current row


Replace or cancel command

Here is an example of replacing the character where the cursor is located: to replace the character where the cursor is located with B, first press r and then press B.

R replaces the character from where the cursor is located until Esc ends.

U cancel the previous operation. First, you have not saved the file. The file is still in memory and has not been synchronized to the hard disk.

Ctrl + r redo the previous operation

. (Decimal point) Repeat the previous operation, for example, repeat deletion, duplicate Paste

Replace or SEARCH Command

/String: searches for the specified string backward. case-insensitive: set ic is ignored during search. Cancel: set noic

N turning back

N forward from the back

? String search string up


: % S/old/new/g Replace the specified string in full text, and old is the keyword to be replaced.

: N1, n2s/old/new/g Replace the specified string within a certain range

: % S/old/new/c Replace the specified string in full text, but you will be asked if you are sure


Save and exit

ZZ: wq shortcut

: W new_filename save as the specified file

: Wq! Forcibly Save the modification and exit [root/file owner]

: Q! Do not save and exit

: [Filename] Save the file

: R [filename] reads data from another file in the edited data, adding the content of the file filename to the end of the row where the cursor is located

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.