Vi command details

Source: Internet
Author: User

Vi usage
1. cursor h left j down k up l right
Set nu: display the row number (set nonu) 21: cursor stops at the specified row
21G line N (G to the end of the file, 1G to the file header) If you want to move the cursor to the first line of the file, then press 1G
H screen head
M screen center
L screen bottom
^ Or shift + 6 rows first
$ Or shift + 4 rows at the end
Ctrl + f flip-down
Ctrl + B flip

2. Input (input mode)
O move the cursor down to another line
O (uppercase letter o) inserts an empty row on the row where the cursor is located
I insert a letter in front of the cursor
A. Insert a new letter behind the cursor
<Esc> exit the insert status.

3. Modify and replace
R to replace one character
Dd: delete rows and cut rows (delete 5 rows in 5dd)
Delete 5 to 10 rows (including 5th rows and 10th rows) from 5 to 10 days)
X delete a character
Dw deletes words and cut words. (3 DWS delete 3 words)
Cw replaces a word. (Difference between cw and dw. After cw deletes a word, it directly enters the editing mode, while dw still remains in the command mode after deleting the word)
Cc replaces one line
C. Replace the cursor with the end of the row.
Yy copy the row (the usage is the same as Y, see the downstream)
Y: move the cursor to the position of the row to be copied, and press yy. When you want to paste it, move the cursor to the previous position where you want to copy it, and then press p
Yw
P paste under the current row
1, 2O3 copy Row 1, 2, and 3
4, 5 rows move 4, 5 rows after 6
U when your previous command operation is an incorrect operation, you can press the u key to restore it. Only once
R file2 insert another file at the cursor

~ Convert letters into uppercase letters
J. You can connect the current row to the next row.
/Search for matched strings from top to bottom
? Searches for matched strings from the bottom up.
N continue searching
1, $ s/old/new/g replace full text (or % s/old/new/g)
(1 indicates starting from the first line) if there is no g, it will be replaced only once.

3. Save and quit
W disk storage
W newfile: New File
Log on to the wq disk and exit VI (or ZZ or X)
Q! Force exit from non-storage disk

Author: "ihuangweiwei"
 

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.