[Common Linux commands 9] vi usage 1

Source: Internet
Author: User

VI has three working modes: Command mode, insert mode, and edit mode.

Enter the command: vi + file name to start VI. The default mode is command mode.

 

Enter I to enter the insert mode, and Press ESC to return to the command mode.

 

Command mode

INSERT command

A insert text behind the cursor

A. Insert text at the end of a row

I insert text before the cursor

I insert text at the beginning of a row

O insert text under the cursor

O insert text on the cursor

 

Move cursor

H move to left

J move down

K move up

L move to the right

 

$ Move to the beginning of a row

0 to the end of the row

 

H jump to top

M jump to the middle end

L jump to the lower end

 

Jump to specific line

: Set nu

: Set Nonu cancel row number

Gg to the first line

G to the last line

Ng to n

: N to row n

 

 

DELETE command

X Delete cursor characters

NX Delete n characters after the cursor starts

 

Dd deletes the row where the cursor is located.

NDD deletes n rows after the cursor starts.

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

DG deletes the content from the beginning to the end of the cursor.

 

: N1, n2d Delete content from line N1 to line N2

 

Copy, cut, and paste

YY copy the current row

Nyy copies the cursor and N rows below

 

DD: Cut the current row

NDD cut the cursor and N rows below

 

P paste the cursor under the row

P paste to the row where the cursor is located

 

Replacement and Revocation

R replaces the character of the cursor

R starts from the character where the cursor is located and ends with pressing ESC.

U undo the previous operation

 

Search and replace

/Search for rows related to the keyword by keyword. Press n to view the next row and press n to view the previous row.

: Case Insensitive for set IC search

: Set noic disable ignore case sensitivity

 

: % S/old/new/g full-text replacement

: N1, N2s/old/new/g only replace N1 to N2

Note: The last g can be changed to C. C indicates whether to replace the G.

 

Save and exit

: WQ exit save type (shortcut: zz)

: Q exit without saving the input

: W save and do not exit

: W: Save the file name

Note: If you do not have the required permissions, add them later !, But only valid for root and owner

 

 

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.