Common VI commands

Source: Internet
Author: User

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: 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

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.