Linuxvi editor common instruction set

Source: Internet
Author: User
Efficiency. Vi is short for "visualinterface" and vim is viIMproved (enhanced version vi ). In general system management and maintenance, vi is enough. if you want to use code to highlight it, you can use vim. What is VI?

Vi (vim) is a commonly used editor on Linux. by default, vi (vim) is installed in many Linux distributions ). There are many vi (vim) commands, but if they are used flexibly, the efficiency will be greatly improved. Vi is short for "visual interface", and vim is vi IMproved (enhanced version vi ). In general system management and maintenance, vi is enough. if you want to use code to highlight it, you can use vim.

Vi common instruction set:

1. Open, save, and close a file (used in vi command mode)

Vi filename // open the filename File
: W // Save the file
: W vpser.net // save it to the vpser.net file
: Q // exit the editor. if the file has been modified, run the following command:
: Q! // Exit the editor and do not save
: Wq // exit the editor and save the file

2. Insert text or line (in vi command mode, run the following command to enter the insert mode. press ESC to exit the insert mode)
A // add text to the right of the current cursor position
I // add text to the left of the current cursor position
A // add text at the end of the current row
I // add text at the beginning of the current line (the beginning of a non-null character)
O // create a new row above the current row
O // create a new row under the current row
R // replace (overwrite) the current cursor position and subsequent text
J // merge the row where the cursor is located and the next row as one line (still in command mode)

3. move the cursor (used in vi command mode)

1. use the up, down, and left direction keys

2. in command mode, h goes to the left, j goes down, k goes up, and l goes to the right.
Space key to the right, Backspace to the left, Enter to the next line first,-to move to the previous line first.

4. delete or restore characters or lines (used in vi command mode)

X // delete the current character
Nx // delete n characters starting from the cursor
Dd // delete the current row
Ndd // delete n rows including the current row down
U // undo the previous operation
U // undo all operations on the current row

5. search (used in vi command mode)

/Vpser // search for a vpser string under the cursor
? Vpser // search for a vpser string from the cursor
N // search down the previous search action
N // search for the previous search action

6. jump to a specified line (used in vi command mode)

N + // jump n rows down
N-// jump n rows up
NG // jump to the row whose row number is n
G // jump to the bottom of the file

7. set the row number (used in vi command mode)

: Set nu // display the row number
: Set nonu // undisplay the row number

8. copy and paste (used in vi command mode)

Yy // copy the current row to the cache. you can also use "ayy copy". "a is the buffer, and" a "can be replaced with any letter from a to z, you can complete multiple replication tasks.
Nyy // Copy the n rows of the current row to the buffer. you can also use "anyy copy". "a is the buffer, and" a "can be replaced with any letter from a to z, you can complete multiple replication tasks.
Yw // Copy the characters starting from the cursor to the end of the word.
Nyw // Copy the n words starting from the cursor.
Y ^ // copy the content from the cursor to the beginning of the line. VPS detective
Y $ // copy the content from the cursor to the end of the row.
P // paste the content in the clipboard after the cursor. if the preceding custom buffer is used, we recommend that you paste it using the "ap.
P // paste the content in the clipboard before the cursor. if you use the custom buffer above, we recommend that you use the "aP" for pasting.

IX. replacement (used in vi command mode)

: S/old/new // replace the old
: S/old/new/g // replace all the old in the row with new
: N, m s/old/new/g // replace all the old values from n to m with new
: % S/old/new/g // replace all old files in the current file with new

10. edit other files

: E otherfilename // edit the file named otherfilename.

11. modify the file format

: Set fileformat = unix // modify the file to unix format. for example, ^ M will appear in the text file under windows in linux.

12. commonly used Vi instruction diagram

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.