Common vi commands, vi

Source: Internet
Author: User

Common vi commands, vi

Common vi commands

1. vi Mode
A) Normal Mode: when vi processes a file, it enters the normal mode as soon as it enters the file.
B) editing mode: In normal mode, you can delete, copy, and paste files, but cannot edit them. And press 'I, I, o, O, a, A, r, R'.
The editing mode is only available after the letter is entered. Generally, in linux, when you press the above letter, 'insert' or 'replace 'appears in the lower left corner.
Enter any text to the file. To return to normal mode, press the [ESC] key.
C) command line mode: In general mode, enter ":" or ?", You can move the cursor to the bottom row. In this mode, you can search for data and read,
Save disks, delete a large number of characters, exit vi, and display row numbers.
2. Summary of common vi commands:
2.1 Normal Mode
A) move the cursor:
--> Top, bottom, left, and right direction keys
--> Pagedown/pageup button
--> Number 0: move the cursor to the beginning of the current row
--> $: Move the cursor to the end of the current row.
--> G: Move to the last line of the file nG: n is a number, move to the nth line of the file.
--> Gg: the first line to move to this file is equivalent to 1G.

B) search and replace
-->/Word: query a string named word from the cursor down. Next n, last #
-->: N1, n2s/word1/word2/g: n1 and n2 are numbers. Search for the string word1 between line n1 and line n2,
And replace the 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 replaces the string with word2.
A prompt is displayed before replacement to check whether the conform needs to be replaced.
C) delete, copy, and paste
--> X, X: in a row, x deletes one character (equivalent to the del key) and X deletes one character (equivalent to the backspace key ).
--> Dd: Delete the entire row where the cursor is located.
--> Ndd: n is a number. Delete down n columns from the cursor.
--> Yy: copy the row where the cursor is located.
--> Nyy: n is a number. Copy the n rows down the cursor.
--> P, P: p: paste the copied data to the next row of the cursor, and P is pasted on the previous row of the cursor.
--> U: Restore the previous operation
--> CTRL + r: redo the previous operation.
--> Decimal point '.': Repeat the previous action.
2.2 edit mode:
A) I, I: insert the input text at the position of the cursor, and the existing text is backward. I is 'insert from the current cursor ', I is 'insert from a non-space character in the current row '.
B) a, A: a is 'insert from the next character at the cursor '. A Is 'insert from the last character in the row where the cursor is located '.
C) o, O: The English o is case sensitive. O is 'insert a new row in the next row of the current cursor '. O indicates 'insert a new row into the previous row of the current cursor '.
D) r, R: Replace: The character where the cursor is located. R: always replace the character of the cursor until the esc key is pressed.
E) ESC: enter normal mode.
2.3 command mode:
A): w: Write the edited data to the hard disk.
B): q: Leave vi
C): q! : Force exit, not stored
D): wq: store and exit
E): wq! : Force storage before leaving

F): set nu: displays the row number.

G): set nonu: Cancel row number

H): r filename: add all content in filename to the current file.

3. Add command lines to vim
3.1 block selection (visual block)
Select the v character to display the reversed IP address of the cursor
Line V is selected, and the line through which the cursor passes is reversed
Ctrl + v block selection, you can select data in a rectangle
Y: The reverse IP address of the replication.
D. Delete the anti-whitelist.
3.2 multi-file editing
: N: edit the next file
: N: edit the previous file
: Files: Lists All files opened by vim.
3.3 Multi-Window functions
: 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 + wj press ctrl first, then press w, open all the buttons, and then press j, then the cursor can be moved to the window below
Ctrl + wk is the same as above, but move the cursor to the above window
Ctrl + wq is actually: q ends and leaves.


Common vi commands

Basic operations of vi
A) Go to vi

After the system prompts you to enter the vi and file name, you will be taken to the vi full screen editing screen:

$ Vi myfile

Note that after entering vi, you are in command mode. You must switch to Insert mode to Enter text. People who use vi for the first time will want to move the cursor first with the upper and lower right keys. As a result, the computer keeps beeping and getting angry with themselves. So after entering vi, do not tamper with the mouse, switch to "Insert mode!

B) switch to Insert mode to edit the file

Click "I" under "command mode" to enter "Insert mode". Then, you can enter the text.

C) Insert switchover

You are currently in "Insert mode", and you can only enter text all the time. If you find that you have entered an error! To move the word back with the light mark key, you must first Press ESC to switch to command mode and then delete the text.

D) Exit vi and save the file

Under "command mode", click ":" colon to enter "Last line mode". For example:

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

: Wq (enter "wq" to save the disk and exit vi)

: Q! (Enter q !, Force exit vi without saving the disk)

3. command mode function key
1). insert mode

Press "I" to switch to the insert mode "insert mode". Press "I" to enter the insert mode. The input file starts from the current position of the cursor;

After you press "a" to enter the insert mode, the text is entered starting from the next position where the cursor is currently located;

After you press "o" to enter the insert mode, a new row is inserted and text is entered from the beginning of the line.

2) switch from insert mode to Command Line Mode

Press ESC.

3) move the cursor

Vi can be moved up, down, left, and right directly with the cursor on the keyboard, but the regular vi uses lowercase letters "h", "j", "k", and "l 」, the cursor is controlled to move one cell to the left, down, up, and right respectively.

Press ctrl + B to move the screen to the back.

Press ctrl + f to move the screen to the front.

Press ctrl + u to move the screen to the back half of the page.

Press ctrl + d to move the screen half to the front.

Press the number "0": to move to the beginning of the article.

Press G to move to the end of the article.

Press "$" to move to the end of the row where the cursor is located ".

Press ^ to move the cursor to the beginning of the row"

Press w to jump to the beginning of the next word

Press "e": move the cursor to the end of the next word

Press "B": the cursor returns to the beginning of the previous word

Press # l to move the cursor to the # position of the row, such as 5l and 56l.

4). delete text

"X": each time you press the button, the "Next" character of the cursor is deleted.

"# X": for example, "6x" indicates deleting the "Next" 6 Characters of the cursor position.

"X": uppercase X. Each time you press it, the "front" character of the cursor is deleted.

"# X": for example, "20X" indicates the position where the cursor is located, which is a string of 20 characters.

Dd: Delete the row where the cursor is located.

「 # Dd 」: delete from the row where the cursor is located # Row

5). Copy

"Yw": copy the character at the end of the cursor to the buffer zone.

# Yw: Copy # words to the buffer zone

"Yy": copy the row where the cursor is located to the buffer zone.

... The remaining full text>
 
Common vi commands

Basic operations of vi
A) Go to vi

After the system prompts you to enter the vi and file name, you will be taken to the vi full screen editing screen:

$ Vi myfile

Note that after entering vi, you are in command mode. You must switch to Insert mode to Enter text. People who use vi for the first time will want to move the cursor first with the upper and lower right keys. As a result, the computer keeps beeping and getting angry with themselves. So after entering vi, do not tamper with the mouse, switch to "Insert mode!

B) switch to Insert mode to edit the file

Click "I" under "command mode" to enter "Insert mode". Then, you can enter the text.

C) Insert switchover

You are currently in "Insert mode", and you can only enter text all the time. If you find that you have entered an error! To move the word back with the light mark key, you must first Press ESC to switch to command mode and then delete the text.

D) Exit vi and save the file

Under "command mode", click ":" colon to enter "Last line mode". For example:

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

: Wq (enter "wq" to save the disk and exit vi)

: Q! (Enter q !, Force exit vi without saving the disk)

3. command mode function key
1). insert mode

Press "I" to switch to the insert mode "insert mode". Press "I" to enter the insert mode. The input file starts from the current position of the cursor;

After you press "a" to enter the insert mode, the text is entered starting from the next position where the cursor is currently located;

After you press "o" to enter the insert mode, a new row is inserted and text is entered from the beginning of the line.

2) switch from insert mode to Command Line Mode

Press ESC.

3) move the cursor

Vi can be moved up, down, left, and right directly with the cursor on the keyboard, but the regular vi uses lowercase letters "h", "j", "k", and "l 」, the cursor is controlled to move one cell to the left, down, up, and right respectively.

Press ctrl + B to move the screen to the back.

Press ctrl + f to move the screen to the front.

Press ctrl + u to move the screen to the back half of the page.

Press ctrl + d to move the screen half to the front.

Press the number "0": to move to the beginning of the article.

Press G to move to the end of the article.

Press "$" to move to the end of the row where the cursor is located ".

Press ^ to move the cursor to the beginning of the row"

Press w to jump to the beginning of the next word

Press "e": move the cursor to the end of the next word

Press "B": the cursor returns to the beginning of the previous word

Press # l to move the cursor to the # position of the row, such as 5l and 56l.

4). delete text

"X": each time you press the button, the "Next" character of the cursor is deleted.

"# X": for example, "6x" indicates deleting the "Next" 6 Characters of the cursor position.

"X": uppercase X. Each time you press it, the "front" character of the cursor is deleted.

"# X": for example, "20X" indicates the position where the cursor is located, which is a string of 20 characters.

Dd: Delete the row where the cursor is located.

「 # Dd 」: delete from the row where the cursor is located # Row

5). Copy

"Yw": copy the character at the end of the cursor to the buffer zone.

# Yw: Copy # words to the buffer zone

"Yy": copy the row where the cursor is located to the buffer zone.

... The remaining full text>
 

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.