Vi Common Commands List

Source: Internet
Author: User

Basically VI can be divided into three states, namely the command mode, the input mode (Insert modes) and the last line mode, the function of each mode is as follows:

1) Command mode

?

Controls the movement of the screen cursor, the deletion of characters, words, or lines, moving and copying a section and entering insert mode, or to last line mode.

?

2) input modes (Insert mode)

?

Only in the Insert mode, you can do text input, press the "esc" key to return to the command mode.

?

3) Last-line mode

Save or Exit VI, or you can set the editing environment, such as finding a string, listing line numbers ... such as

In general, however, we simplify the VI into two modes when we use it, that is, the last Linemode is also counted in command mode.


Basic operation of VI

Enter VI

After the system prompt symbol to enter VI and file name, go to the VI Full screen editing screen:

$ VI myfile

However, it is important to note that after you enter VI, you are in command mode, and you want to switch to input mode to enter text. First Use VI people will want to use the next key to move the cursor, the result of the computer has been beep beep, the air of their own half-dead, so enter the VI, do not move, switch to "input mode (Insert mode)" Say it!

Switch to input mode (Insert mode) to edit the file

Press the letter "i" under Command mode to enter "Input mode", at which point you can start typing text.

Toggle of Insert

Currently in "Input mode", you can only enter text, if you find the wrong word! To move back with the cursor key, delete the word, then click the "esc" key to go to "command mode" and then delete the text.

?

Exit VI and save file

?

Under Command mode, click the ":" colon key to enter "last line mode", for example:

: w filename (enter "w filename" to save the article with the filename you specified)

: Wq (input "wq", save and Exit VI)

: q! (Enter q!, do not save the mandatory exit VI)

?

Command mode function key

1). Input mode

Press "i" to switch into input mode "insert mode", press "I" Enter the input mode is the beginning of the cursor from the current position to enter the file;

When the input mode is entered by "a", the input text starts at the next position of the cursor.

When you press "o" to enter input mode, you insert a new line and enter text from the beginning of the beginning.

2). switch from Input mode to command mode

Press the "esc" key.

3). Move the cursor

VI can be directly on the keyboard with the cursor to move up and down, but the normal VI is the lowercase English letter "h", "j", "k", "l", respectively, control the cursor left, bottom, upper, and right one grid.

Press "ctrl"+"b": The screen moves one page to the back.

Press "ctrl"+"f": The screen moves one page to the front.

Press "ctrl"+"u": The screen moves the half page toward the back.

Press "ctrl"+"d": The screen moves the half page toward the front.

?

?

"0" by number: Moves to the beginning of the article.

Press "g": Move to the end of the article.

Press "$": Moves to the end of the line where the cursor is located.

Press "^": Moves to the beginning of the line where the cursor is located

Press "w": Cursor jumps to the beginning of the next word

Press "e": Cursor jumps to the end of the next word

Press "b": Cursor back to the beginning of the last word

Press #l: The cursor moves to the first # position of the line, such as: 5l,56l.

4). Delete text

"x": Each time you press the cursor, delete the "after" character at the position where the pointer is located.

#x: For example, "6x" represents the "after" 6 characters of the location where the cursor was deleted.

"x": Uppercase X, each time it is pressed, deletes the "front" character at the location of the cursor.

"#X": for example, "20x" represents the "front" 20 characters of the location where the cursor was deleted.

"dd": Delete the line where the cursor is located.

"#dd": Deletes the # line starting at the line where the cursor is located

5). Copy

"yw": Copies the characters from the cursor to the end of the word into the buffer.

"#yw": Copy # words to Buffer

"yy": Copy cursor line to buffer.

"#yy": for example, "6yy" represents a copy of 6 lines of text from the line where the cursor is located.

"p": Paste the characters in the buffer to the cursor location. Note: All copy commands related to "Y" must be mated with "P" to complete the copy and paste function.

6). Replace

"r": Replaces the character at which the cursor is located.

"r": Replaces the character where the cursor is located until the "esc" key is pressed.

7). Reply to Last action

"u": If you mistakenly execute a command, you can press "u" immediately to go back to the previous action. Multiple replies can be performed by pressing "U" multiple times.

8). Change

"cw": Change the word-to-tail at the cursor location

"c#w": For example, "c3w" represents a change of 3 words

9). Jump to the specified line

"ctrl"+"g" lists the line number of the line where the cursor is located.

"#G": for example, "15g", which means moving the cursor to the beginning of the 15th line of the article.

Last line Mode command brief

Before using "last line mode", remember to press "esc" to make sure you are under "command mode" and then press ":" Colon to enter "last line mode".

A) List line numbers

"set nu": After you enter "set nu", the line numbers are listed before each line in the file.

B) jump to a line in the file

The "#":"#" number represents a number, enter a number after the colon, and then press ENTER to jump to the line, such as entering the number 15, and then enter, you will jump to the 15th line of the article.

C) Find characters

"/Keyword: First press the"/"key, and then enter the character you want to look for, if the first keyword is not what you want, you can always press"n"will look back to the keyword you want.

?

"? keyword": Press "?" first Key, and then enter the character you want to find, if the first keyword is not what you want, you can always press "n" will look forward to the keyword you want.

D) Save the file

"w": Enter the letter "w" the colon to save the file.

E) Leave VI

"q": Press "q" is to exit, if you cannot leave VI, can be "q" followed by a "!" Forced to leave VI.

"wq": Generally recommended to leave, use with "w", so you can also save the file when exiting.

?

?

VI Command List

1), the following table lists the functions of some keys in the command mode:

H move the cursor one character to the left

L Move cursor one character to the right

K Move the cursor up one line

J Cursor moves down one line

^ cursor moves to the beginning of the line

0 Number "0", the cursor moves to the beginning of the article

G cursor moves to the end of the article

$ cursor moves to end of line

Ctrl+f Front Flip Screen

Ctrl+b Turn back the screen

Ctrl+d forward Half screen

Ctrl+u Back half screen

I insert a character before the cursor position

A the next character at the cursor position begins to increment

o Insert a new line and enter it from the beginning

ESC fallback from input State to command state

X Delete the character following the cursor

#x the # characters after the cursor is deleted

X (uppercase x), delete the character in front of the cursor

#X Delete the # characters before the cursor

DD Delete the line where the cursor is located

#dd Remove the # line from the number of lines that the cursor contains

YW a word at the location where the cursor is copied

#yw the # character where the cursor is copied

YY the line where the cursor is copied

#yy Copy the # line from the number of lines where the cursor is located

P Paste

U Cancel operation

CW change a word at the cursor location

#cw change the # Word where the cursor is located

2), the following table lists some instructions in the line command mode

W filename stores the file being edited as filename

WQ filename stores the file being edited as filename and exits VI

Q! Discard all changes, exit VI

Set NU Display line number

Or? Find, enter what you are looking for in/after

N and/or, if the search is not the keyword you are looking for, press N or backward (with/to) or forward (with) to continue looking until you find it. For the first use VI, there are a few notes to remind:

1, with vi open the file, is in "command mode", you want to switch to "input mode" to enter text.

Toggle Method: Click the letter "i" under "command mode" to enter "input mode", at which point you can start typing.

2, after editing, you need to switch from the input mode to the command mode to save the file, switching method: Press the "esc" key.

3. Save and exit the file: Enter in command mode: WQ! (Don't forget to wq the front:)

Vi Common Commands List

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.