Vim commands used in Linux

Source: Internet
Author: User

Vim working mode

VI file name into command mode

I a O into insert mode

ESC key back to command mode

: Enter edit mode

Add line number: Set Number/nu

: Wq Save Exit

Insert command

A specifier insert in the word cursor

A at the end of the line where the cursor is inserted

I match either insert in the word cursor

I Insert at the beginning of the line where the cursor

o Insert a new line under the cursor

O insert a new line on the cursor

: Set Nu Sets line number

: Set Nonu Cancel line number

GG to First line

G to last line

NG (: N) to Nth row

$ move to end of line

0 move to the beginning of the line

X Delete the character at the cursor location

NX removes the n characters after the cursor is located

DD deletes the cursor in the row

NDD Delete N rows

DG deletes the line at the cursor to the end of the file

D Delete the contents of the cursor at the end of the line

: n1,n2d deletes a specified range of rows

YY copy when moving forward

Nyy Copy the current row following n rows

DD Cut when moving forward

NDD cuts the current row following n rows

P paste below the line where the cursor is located

P paste to the top of the line where the cursor is located

R replaces the character at which the cursor is located

R replaces the character at the beginning of the cursor, ESC exits

U Cancel the previous action

/String to search for the specified string (: Ignore case when set IC searches)

N Next (Next)

:%s/old/new/g full text Replace specified string

:%s/old/new/c full text Replace specified string (ask for confirmation)

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

: N1,N2S/OLD/NEW/C replaces the specified string within a certain range (asking for confirmation)

: W Save changes

: W new_filename Save as specified file

: Wq Save changes and exit

ZZ shortcut keys, save changes and exit

: q! Do not save changes to exit

: wq! Save changes to the read-only file and exit (the file owner and root can be used)


Vim Tips

: R file name imports the specified file contents into the file being edited, where the cursor is located

:!which command edit state to see the absolute path of the command and other information

: R!date Import Current time

: Map definition shortcut keys

: Map ctrl+^+ Letter Command Combination

: Map ^p i#<esc> Shortcut Comment Line

: Map ^b 0x Uncomment

: Map ^h [email protected]<esc> inserting a mailbox at the cursor

Continuous comment lines

: n1,n2s/^/#/g comment on multiple lines from N1 to N2
: n1,n2s/^#//g cancellation of comments from N1 to N2
: n1,n2s/^/\/\//g with//comment multiple lines

Replace

: AB mymail [email protected] automatically replaces all input mymail with [email protected]

Permanently sets the configuration file for the shortcut. VIMRC

Creation or change is done in the home directory

Vim commands used in Linux

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.