Common shortcut keys of vi

Source: Internet
Author: User

VI can be divided into command mode, insert mode, and last line mode)

Insert switchover → command mode, Press ESC

Exit VI and save files
In command mode, you can press the colon ":" to enter the last line mode. For example:
: W filename (enter "w filename" to save the article to the specified filename)
: WQ! (Enter "WQ". Because the file name testfile has been specified at the time of access, it will write testfile and leave VI)
: Q! (Enter "Q !", Force exit and discard edited files)


Command mode function key list
When introducing the command mode command, the command is followed by a function key with the word "commonly used" to indicate commonly used VI commands,
(1)I, A, o switch to insert mode. [Super common]

I: switch to the input mode. The inserted content is before the cursor.

A: switch to the input mode. The inserted content is after the cursor.

O: switch to the input mode and Insert a new row from the first line.


(2) move the cursor
VI can be moved up, down, left, right, and left directly using the optical key on the keyboard, but the regular VI is a lowercase English letter.
H, J, K, and l, respectively, control the left, down, up, and right shifting of the cursor.
(3) Delete text
X: each time the cursor is deleted, the next character is deleted. [Extraordinary use]
# X: for example, the 6X table deletes the next six characters of the cursor position. [Common]

X: X of the big character. Each time the cursor is deleted, the first character is deleted.
# X: for example, in the 20x table, the first 20 characters of the cursor position are deleted.
DD: Delete the row where the cursor is located. [Extraordinary use]
# DD: for example, the 6dd table deletes six lines of text from the row where the cursor is located. [Common]
(4) Copy
YW: copy the character from the cursor position to the end of the word to the buffer zone.
(Unlike # X and # X)
P: paste the characters in the buffer to the cursor position (the command 'yw' and 'P must be used together ).
YY: copy the row where the cursor is located. [Extraordinary use]

P: copy a single row to where you want to paste it. (The command 'yy' and 'p' must be used together)

(5) List row numbers
Set nu: After "set nu" is input, the row number is listed before each row of the article.
(6) jump to a line of the article
#: The well number represents a number. Enter a number before the ":" symbol in last line mode and press enter to jump to this line,
For example:15 [enter] will jump to the 15th line of the article. [Common]
(7) Search for strings
/Keyword: First press/and then enter the word you want to search for. If the keyword you are looking for the first time is not as close as possible, you can press n until you find the keyword you want.
? Keyword: First press ?, Enter the word you want to search. If the keyword you want for the first time is not what you want, you can press n to search for the keyword you want.
(8) saving files
W: Press W before the last line mode prompt ":" To save the file. [Extraordinary use]
#,# W filename: If you want to extract a part of the article and save it as another file, use this command # to indicate the row number, for example, 30, 50 w nice,
Add the 30th ~ 50 rows are saved as nice files.
(9) Exit
Q: Press Q to exit. Sometimes, if you cannot exit Vi, you can use "! : Force exit VI, such as "Q !"
QW: it is generally recommended that you use it with w when you exit. files can be stored when you exit. [Common]

Common shortcut keys of vi

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.