VI Editor Common commands

Source: Internet
Author: User

1. order to enter VI
1) "VI filename": Open or edit a file named filename, enter command mode
2) "VI +n filename": Opens the file and places the cursor at the beginning of nth
3) "VI + filename": Open the file and place the cursor at the beginning of the last line
4) "VI +/pattern filename": Opens the file and places the cursor at the first string matching the pattern
5) "Vi-r filename": A system crash occurred during the last edit with VI, restoring filename
6) "VI filename....filename": Open multiple files and edit them sequentially

2. Exit VI:
1) Enter ": q!" in command mode: Force exit, do not save the result of this modification
2) Enter ": Wq" in command mode: Exit after saving current contents

3. Enter Command mode:
1) The command mode when entering VI
2) Enter method "ESC" from input mode

4. Enter input mode
1) "I": enter input mode and insert text before cursor
2) "I": Enter input mode and insert text at the beginning of the current line
3) "A": Enter input mode and insert text after cursor
4) "A": Enter input mode and insert text at the end of the current behavior
5) "O": Enter input mode and insert text in a new line below the current line
6) "O": Enter input mode and insert text on a new line above the current line

5. Enter last line mode
In command mode, enter ":"

6. Delete (to be performed in command mode)
1) "x": Delete the character of the cursor
2) "X": one character before the cursor is deleted
3) "DW": Delete a word starting from the cursor
4) "DD": Delete cursor in row
5) "Do": Delete to the beginning of the line
6) "d$": Delete to the end of the line

7. Execute shell command line in VI (to be done in the last line mode)
“:! Command

8. Search (in command mode)
1) "FA": Search for a position that appears next to the current line
2) "Fa": Search for a position that appears on the previous line in the current row
3) "Ta": Search for a character before the next occurrence
4) "Ta": Search for characters after the previous occurrence of a
5) ";": Repeat the most recent search command
6) "/pattern": Search for pattern from the beginning of the cursor at the end of the file
7) "? Pattern": Search for pattern from the beginning of the cursor to the top of the file
8) "N": Repeat the last search command in the same direction
9) "N": Repeats the last search command in the opposite direction

9. Replace (in the last line mode)
1) ": s/p1/p2/g": Replaces all P1 in the current row with P2
2) ": n1,n2s/p1/p2/g": Replace all P1 in line N1 to N2 with P2
3) ": g/p1/s//p2/g": Replace all P1 in the file with P2

10. Replace (in command mode)
1) "R" replaces the current character
2) "R" replaces the current character and its characters until you press ESC

11. Move cursor (in command mode)
1) "H": Move the cursor one character to the left
2) "L": Move the cursor right one character
3) "Space": Move the cursor right one character
4) "Backspace": the cursor moves left one character
5) "K" or "ctrl+p": Move the cursor up one line
6) "J" or "Ctrl + N": Move the cursor down one line
7) "Enter": Move the cursor down one line
8) "W" or "W": Move the cursor right one word to the beginning of the word
9) "B" or "B": the cursor moves left one word to the beginning of the word
"E" or "E": the cursor moves right one word to the end of the word
11) ")": Move cursor to end of sentence
12) "(": the cursor moves to the beginning of the sentence
13) "}": Move the cursor to the beginning of the paragraph
14) "{": Move cursor to end of paragraph
"NG": the cursor moves to the beginning of nth
"n+": the cursor moves down n rows
"N": the cursor moves up n rows
"n$": the cursor moves to the end of the nth line
"H": Move the cursor to the top line of the screen
"M": Move the cursor to the middle line of the screen
"L": the cursor moves to the last line of the screen
22) "0": (note is the number 0) the cursor moves to the beginning of the current line
23) "$": Cursor moves to the end of the current line

12. "~": Change the case of the character of the cursor

13. ". : Repeat the previous action

14. "<<": Move the current line to the left

15. ">>": Move the current line to the right

16. To the file locking (last line mode)
": X": Enter the password after the ENTER key prompt appears. The next time you enter the file, the format
For "vi–x filename", you will be prompted to enter the password.

17. Simplified input (last line mode)
": AB String Strings": use string instead of strings when editing
Eg: ": AB Rd Redstone Info": "Redstone info" will appear instead of RD when you enter "RD" in the text later and return to the

18. Custom keyboard commands (last line mode, less dangerous, not recommended)
": Map Keys New_seq"

19. Display line numbers (in the last row mode, coding works well)
": Set number" displays line numbers

20. Looking for a function when coding with VI
First, in the shell environment with the ctags command to the current directory of C original program scanning, generate tags file
eg:$ Ctags *.c
Then, in VI can be the command ": Ta fun_name", you can directly open the file where the function fun_name, and put the cursor at the beginning of the function

21. Insert file (last line mode)
": R filename": Inserts the filename into the current file position

22. Direct jump (last line mode)
": N": N is the number of rows, jump directly to the nth row

23. Row copy (last line mode)
": 2,9 Co 10": Copy lines 2nd through 9th to line 11th (note the 11th line, not the 10th line)

24. Row clipping (last row mode)
": 2,9 M 10": Move line 2nd through Line 9th to line 11th (note 11th line, not 10th line)

VI Editor Common 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.