Common VI usage

Source: Internet
Author: User

Normal Mode

I-> editing mode

:-> Command mode

The ESC key can be returned from the editing or command mode to the general mode.


In normal mode,
Cursor
Move: always valid →
Page flip: Pageup/Pagedown
0: move the cursor to the beginning of the current row
$: Move the cursor to the end of the current row
G: move the cursor to the end of the file.
NG: move the cursor to line N of the file.
GG: move the cursor to the first line of the file (equivalent to 1G)
Search and replace
? Word: query a string named word from the cursor up. You can repeat up and down by N, N
/Word: query a string named word from the cursor down. You can repeat down by N, N and query up
: N: the nth line of the object.
: N1, N2s/word1/word2/G: N1 and N2 are numbers. Search for the word1 string between line N1 and line N2, and replace this string with word2.
: 1, $ S/word1/word2/G: searches for the word1 string from the first row to the last row, and replaces the string with word2.
: 1, $ S/word1/word2/GC: searches for the word1 string from the first row to the last row, and requests the user to confirm before replacing it with word2
Delete, copy, and paste
X, X: in a row, X deletes one character backward, and X deletes one character forward.
DD: Delete the row where the cursor is located.
NDD: delete n rows from the row where the cursor is located
YY: copy the row where the cursor is located
Nyy: Copy n rows down from the row where the cursor is located
P, P: P inserts data from the clipboard into the row where the cursor is located, and P inserts data into the row where the cursor is located.
U: Restore the previous operation
CTRL + R: redo the previous operation
Decimal point '.': Repeat the previous action

In command mode,
: Set nu-> display row number
: W-> write edited data to the hard disk
: Q-> exit
: Q! -> Force exit
The preceding three commands can be used in combination.

Additional commands
Block Selection
V: display the area where the cursor passes in white
V: select the line through which the cursor goes through
CTRL + V: block selection. You can select data in a rectangle.
Y: copy the anti-whitelist
D: Delete the whitelist.

Multiple windows
: SP [filename]: opens a new window. If filename is added, a new file is opened in the new window; otherwise, the two windows are the same file content.
CTRL + W
J: move the cursor to the window below
K: move the cursor to the window above

Common VI usage

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.