Vim Common Operation Self Summary

Source: Internet
Author: User
Tags save file

Vim basic operation too much, too much to remember at all, or some of the more commonly used operations to make a small note, especially the replacement string operation.

(1) Enter the VIM editor

Vim filename: Opens or creates a new file and places the cursor at the beginning of the first line

Vim +n filename: Opens the file and places the cursor at the beginning of nth

Vim filename....filename: Open multiple files, edit in sequence


(2) Move cursor

VI can be directly with the keyboard cursor keys to move up and down, but the normal VI is a lowercase English letter

H, J, K, L, respectively, control the cursor left, bottom, up, and right to move one grid.

Press CTRL+B: The screen moves backward one page. Common

Press CTRL+F: The screen moves forward one page. Common

Press 0 (number 0): Moves the beginning of the article. Common

Press G: Move to the end of the article. Common

Press $: To move to the end of the line where the cursor is located. Common


(3) Delete text

X: Deletes the next character at the location of the cursor every time it is pressed. [Exceptional]

DD: Deletes the line where the cursor is located. [Exceptional]


(4) Copy

YY: The line where the cursor is copied. [Exceptional]


(5) Restore (undo) Previous Instruction

U: If you mistakenly operate an instruction, you can press u immediately to revert to the previous operation. [Exceptional]

U: Undo all changes to the current line

Introduction to command-line directives before you use command-line directives, remember to press the ESC key to determine that you are already

mode, then press the colon

":" or "/" or "? "One of the three keys enters the Lastlinemode.


(6) Searching for strings

/Keywords: first Press/, then enter the words you want to find , if the keyword you first searched for is not as close as possible, you can always press

N will look down to the keyword you want.? Keyword: press first? , and then enter the word you want to look for if the first time you look for the

The keyword is not what you want, you can press N to look forward to the keyword you want.


(7) Replace string

1, $s/string/replae/g: lastlinemode input "1, $s/string/replace/g" will be the full text of the

String string to replace with replace string, 1, $s means the search interval is the meaning of the article from beginning to finish , G is

Indicates that all substitutions do not have to be confirmed. %S/STRING/REPLACE/C: will also replace the full-text string strings with replace

The string, unlike the above instruction, is,%s and 1, $s is the same function, C is the expression to be replaced before must again

Confirm whether to replace.

1, s/string/replace/g: Replace the string 1 through 20 with the Relpace string.


: S/oldtext/newtext replace OldText with NewText


:%s/vivian/sky/(equivalent to: g/vivian/s//sky/) replaces the first Vivian of each line as Sky

:%s/vivian/sky/g (equivalent to: g/vivian/s//sky/g) replaces all Vivian in each row as Sky (Super Common)




(8) Save text and exit Vim

Command save and/or exit operations

: w save file but do not exit vim

: Wq or ZZ or: x save file and exit Vim

: q! Do not save file, Exit VI





Vim Common Operation Self Summary

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.