Linux under VI command

Source: Internet
Author: User

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

1. General mode: VI when processing a file, entering the file is the general mode. In this mode, you can use the "up and down" key to move the cursor, you can use "delete character" or "Delete whole line" to process the contents of the file, you can also use "copy, paste" to process the file data.

2. Edit mode: In general mode can be deleted, copy, paste and other operations, but unable to edit operations, wait until the "I, I, O, O, A, a, R, R" and other letters will enter the editing mode. Note that, usually in Linux, when the above letter is pressed, the words "insert or replace" appear in the lower 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.

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

1. use VI to enter general mode

[Email protected]]# VI test.txt

Enter "vi+ file name" directly to enter VI General mode

2. Press I to enter edit mode

In edit mode, the word "INSERT" appears at the bottom left of the screen.

3 , press "ESC" key to return to normal mode

Pressing the "ESC" key will immediately find that the-insert-in the lower left corner of the screen is missing.

4. Exit VI Editor

In general mode, press ": Wq" to leave VI after storage, press ": Q" to leave VI for not saving edits. Note When you exit a "read-only" class reminder, you can add "!" after the command. "means" to "force".

VI FileName: Opens or creates a new file and places the cursor at the beginning of the first
VI +n FileName: Opens the file and places the cursor at the beginning of nth
VI + FileName: Opens the file and places the cursor at the beginning of the last line
VI +/pattern FileName: Opens the file and places the cursor at the first string that matches the pattern
Vi-r FileName: The last time you were editing with VI, a system crash occurred, restoring filename
VI filename....filename: Open multiple files, edit them sequentially

Use of VI
--------------------------------------------------------------------------------

First, insert text
┌──┬────────────┐
│ Command │ Description │
├──┼────────────┤
│i│ inserting text match either the current word │
├──┼────────────┤
│i│ inserting text at the beginning of the line │
├──┼────────────┤
│a│ Add text after the current character │
├──┼────────────┤
│a│ Add text at the end of a row │
├──┼────────────┤
│o│ insert a blank line after the current line │
├──┼────────────┤
│o│ insert a blank line before the current line │
├──┼────────────┤
│r│ entering text in rewrite mode │
└──┴────────────┘
Second, move the cursor
┌─────┬───────────┐
│ Command │ Description │
├─────┼───────────┤
│j or DOWN arrow │ Move down one line │
├─────┼───────────┤
│k or up ARROW │ move up one line │
├─────┼───────────┤
│h or LEFT arrow │ move left one character │
├─────┼───────────┤
│l or RIGHT arrow │ move right one character │
├─────┼───────────┤
│w│ Right One word │
├─────┼───────────┤
│w│ Right Moves a space-delimited word │
├─────┼───────────┤
│b│ left one word │
├─────┼───────────┤
│b│ left a space-delimited word │
├─────┼───────────┤
│0│ move to the beginning of the line │
│ctrl-f│ forward Page │
├─────┼───────────┤
│ctrl-b│ back Page │
├─────┼───────────┤
│ng│ to nth line │
├─────┼───────────┤
│g│ to the last line │
└─────┴───────────┘

┌─────┬──────┐
│ Command │ Description │
├─────┼──────┤
│$│ to the end of the line │
├─────┼──────┤
│ (│ to the beginning of the sentence │
├─────┼──────┤
│ ) │ to the end of the sentence │
├─────┼──────┤
│{│ to the beginning of the paragraph │
├─────┼──────┤
│}│ to the end of the paragraph │
└─────┴──────┘

Third, replace the text

┌───┬───────────┐
│ Command │ Description │
├───┼───────────┤
│r│ replacing a character │
├───┼───────────┤
│cw│ Modify Next Word │
├───┼───────────┤
│cnw│ Modify the next n words │
└───┴───────────┘

Iv. delete text  
┌───┬─────────────┐ 
│ command │ description │ 
├───┼─────────────┤ 
│x│ Delete the character   │  under the current cursor;
├───┼─────────────┤ 
├───┼─────────────┤ 
│d$│ Delete the remaining portion of the line after the cursor │ 
├───┼─────────────┤ 

├───┼─────────────┤
│c│ function and d the same difference is completed delete │

││ into insert mode│ after operation
├───┼─────────────┤

│cc│ also deletes the current line and then goes to │

││insert mode│

└───┴─────────────┘
Five, text editing
┌──┬──────────────────────┐
│ Command │ Description │
├──┼──────────────────────┤
│yy│ move a line of text into the default buffer │
├──┼──────────────────────┤
│yn│ Move the next word into the default buffer │
├──┼──────────────────────┤
│ynw│ Move the following n words into the default buffer. │
├──┼──────────────────────┤
│p│ If the default buffer contains a line of text, the current │
insert a blank line after the ││ line wells the sound in the default buffer │
││ paste into this line, if the default buffer contains │
││ multiple words, paste them to the right of the cursor. │
├──┼──────────────────────┤
│p│ If the default buffer contains a line of text, it is current │
││ Insert a blank line in front of the line wells the default buffer in the inner │
││ paste into this line, if the default buffer contains │
││ Multiple words, paste these words to the left of the cursor|

└──┴──────────────────────┘

Vi. Saving and exiting
┌───────────┬───────────────┐
│ Command │ Description │
├───────────┼───────────────┤
│zz│ Save and exit │
├───────────┼───────────────┤
│:w filename│ Write file │
├───────────┼───────────────┤
│:w│ writing Files │
├───────────┼───────────────┤
│:x│ Save (if the current file has been modified) and exit │
├───────────┼───────────────┤
│:q! │ do not save files, direct exit │
├───────────┼───────────────┤
│:q│ exit vi│

└───────────┴───────────────┘

Vii. Replacement and search

1)/word→ looks under the cursor for a string called Word. If you want to find the Eric4ever string, enter/eric4ever to

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

3) n→ "Repeat the previous search action"

4) n→ with N just the opposite, for "reverse" the previous find action

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

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

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

Linux under VI command

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.