Linux system under VI Common command finishing

Source: Internet
Author: User

VI is divided into three modes, namely "General mode", "edit mode" and "Command line command mode".

L General mode: VI processing files, the first entry to the file is a general mode. In this mode, you can use the "up or down" key to move the cursor, you can use the delete character or delete whole line to process the contents of the file, or you can use copy, paste to process the file data.

L edit mode: In general mode can be deleted, copy, paste and other operations, but cannot be edited, to wait until the "I, I, O, O, A, a, R, R" and other letters will enter the editing mode. Note that normally in Linux, when the above letter is pressed, the words "insert or replace" appear at the bottom left of the screen before you can enter characters into the file. When you return to normal mode, you can exit edit mode by pressing the ESC key.

L Command line Command mode: In general mode, enter ": OR/or?" "You can move the cursor to the bottom row, in which you can search for data, and read, save, delete characters, leave VI, display line numbers, and so on are implemented in this mode."

1, use VI to enter general mode

[root@linux]# VI Test.txt

Enter "vi+ filename" to enter VI General mode directly

2, Press I into edit mode

The word "INSERT" appears in the lower left of the screen in edit mode.

3 , press the "ESC" key to return to general mode

Press the "ESC" key immediately will find the screen in the lower left corner of the-insert-disappeared.

4, Exit VI Editor

In general mode Press ": Wq" for storage after leaving VI, press ": Q" for not save edit left VI. Note When you exit the "read-only" class reminder, you can add "!" after the command. "means" coercion ".

Common commands

One, move the cursor

1) H or left direction key (←) → Cursor move one character to the left

2 J or down direction? (↓) → Cursor Move down one character

3 K or upward direction? (↑) → Move the cursor up one character

4 L or right direction? (→) → The cursor moves one character to the right

5 [Ctrl] + [f]→ screen "down" to move one page, equivalent to [Page DOWN] button

6 [Ctrl] + [b]→ screen "up" to move one page, equivalent to [Page UP] button

7) N<space>→n says "number". Press the number and then press the blank? The cursor moves the n characters in the line to the right

8 0→ Number "0": Move to the front character of this line

9) $→ move to the last character in this line

g→ move to the last line of this file

) Ng→n as a number. Move to the nth line of this file (fit: Set Nu)

Gg→ moved to the first line of this file, equivalent to 1G

N<enter>→n is number. The cursor moves down n rows

Ii. Finding and replacing

1)/word→ to the cursor to find a string called Word. To find the Eric4ever string, enter/eric4ever

2)? word→ to find a string above the cursor named word

3) n→ "Repeat the previous lookup action"

4 n→ and N just the opposite, to "reverse" the previous lookup action

5): N1,n2s/word1/word2/g→n1 and N2 are all numbers. Find the Word1 string between the N1 and N2 rows and replace the string with Word2. For example, find eric4ever between lines 1 through 9 and replace it with Eric4ever: ": 1,9s/eric4ever/eric4ever/g"

6): 1, $s/word1/word2/g→ finds the word1 string from the first line to the last line and replaces the string with Word2

7): 1, $s/word1/word2/gc→ to find the Word1 string from the first line to the last line, and replace the character window with Word2, before replacing the prompt dialog box to confirm the replacement

Delete, copy, and paste

1 x, x→ in a line of words, X for backwards? h except one character (equivalent to [del] button), X is forward? h except one character (equivalent to [backspace] key)

2) dd→?h the entire line except the cursor

3) Ndd→n as number.? h except for the Down N column where the cursor is located

4) yy→ the line where the cursor is copied

5) Nyy→n is the number. Copy down n column where cursor is located

6 p, p→p to paste the copied content on the next line of the cursor, p is pasted on the top line of the cursor

7) u→ Restore the previous action

8) [ctrl]+r→ Redo the previous action

9). → Decimal point means to repeat the previous action

★ Edit Mode

1) I, i→ insertion: Inserts the input text at the current cursor place, the existing text will go backwards, where I is "insert from the current cursor," I is "in the current line of the first??" Start inserting at a non-whitespace character.

2 A, a→a as "insert from the next character at the current cursor", A is "insert from the last character in the line where the cursor is located"

3) O, o→o "Inserts a new row at the next line at the current cursor", and O "Inserts a new row on the previous line at the current cursor"

4 R, R→r as "replaces the cursor where the character is," R is "always substituting the text of the cursor until you press ESC"

5) esc→ exit edit mode, return to normal mode

★ Last line instruction mode

1): w→ writes the edited file to the hard disk

2): q→ exit VI

3): wq→ After the preservation of the exit, if: wq! To force Save as exit

4): Set nu→ display line number

5): Set nonu→ suppress line number

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.