Use of the Linux VI editor

Source: Internet
Author: User

VI is the short name of visual interface, it is a text editor under Linux/unix, for example, if you want to edit the file English.txt, you can enter the VI english.txt command under terminal and then enter the editing interface.

1:vi Mode
A) General mode: VI when processing a file, one enters the file, which is the general mode.
b) Edit mode: In general mode can be deleted, copy, paste and other operations, but unable to edit the operation. When you press the ' I,i,o,o,a,a,r,r ', the letters are then entered in edit mode. Usually in Linux, when the above letter is pressed, the words ' INSERT ' or ' REPLACE ' will appear in the lower left to enter any text into the file. To return to normal mode, press [ESC] Key.
c) command-line mode: In general mode, enter ": OR/or?" To move the cursor to the bottom line, in which you can search for data, read, save, delete characters, leave VI, display line numbers, and so on.
2:vi Common Commands Summary
2.1: General mode
A) Move the cursor
1, up and down direction key ↑↓←→
2. Page Pagedown/pageup button
3, number 0: Moves the cursor to the beginning of the current line
4. $: Moves the cursor to the end of the current line
5, G: Move to the last line of this file, Ng:n is a number, move to the nth line of this file
6, GG: Move to the first line of this file is equivalent to 1G

b) Search and replace
1,/word: From the beginning of the cursor, query down a string named word.
2,: n1,n2s/word1/word2/g: N1 and N2 are numbers. Look for N2 between the N1 and Word1 lines and replace the string with Word2.
3,: 1, $s/word1/word2/g: look for the word1 string from the first line to the last line, and replace the string with Word2.
4,: 1, $s/word1/word2/gc: look for the word1 string from the first line to the last line, replace the string with Word2, and display a prompt before replacing to confirm that the user needs to be replaced.

c) Delete, copy, paste
1, X,x: In a row, X is the backward deletion of a character (equivalent to the DEL key), X is the forward deletion of a character (equivalent to the BACKSPACE key).
2, DD: Delete the entire line where the cursor is located.
3, Ndd:n is the number. From the beginning of the cursor, delete the down n column.
4, yy: Copy the line where the cursor is located.
6, Nyy:n is the number. The next n rows where the cursor is copied.
7, p,p:p to paste the copied data to the next line of the cursor, p is affixed to the previous line of the cursor.
8. U: Restore previous operation
9, CTRL + R: Redo the previous operation.
10, decimal point '. ': Repeat the previous action.
2.2: Edit mode:
        1, i, i :  inserts the input text where the cursor is located, and the existing text is backward. i  is ' Insert ' from the current cursor where ',i  is ' to start inserting ' at a non-whitespace space in the current row.
       2, a, a : a  to ' insert from the next character where the current cursor is located '. a  is ' start inserting ' from the last character of the line where the cursor is located.
       3,  o,O :  This is the case of the English O. o Insert a new line at the next line in the row where the current cursor is located. O means ' insert a new line at the top of the line where the current cursor is located '. The
       4, r,r :  replace:r  replaces the character that the cursor is in.  R :  will always replace the character of the cursor until the esc  key is pressed.
       5, esc :  into general mode.
2.3: Command mode:
1,: w: Write the edited data to the hard disk
2,: Q: Leave VI
3,: q! : Forced departure, not stored
4: Wq: Store and leave
5,: wq! : Force storage after leaving

Use of the Linux VI editor

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.