How to use the vi (vim) editor on Linux

Source: Internet
Author: User
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 the abbreviation of visualinterface, and vim is viIMproved (enhanced version of vi ). In the general system... vi (vim) is a very common tool for editing Linux. vi (vim) is installed by default 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 highlight the code, you can use vim vi in three modes: insert mode, command mode, and low-line mode. Insert mode: you can enter characters in this mode. press ESC to return to the command mode. Command mode: you can move the cursor or delete characters. Low-line mode: you can save files, exit vi, set vi, search, and other functions (low-line mode can also be seen as in command mode ). 1. Open, save, and close the file (use 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 file 2, insert text or line (used in vi command mode, run the following command to enter the insert mode, press ESC to exit the insert mode) a // add text I to the right of the current cursor position // add text A to the left of the current cursor position // add text I to the end of the current row // add text at the beginning (first line of non-null characters) O // create a new row on top of the current row o // create a new row under the current row R // replace (overwrite) current cursor position and several subsequent texts J // merge the row where the cursor is located and the next row as a line (still in command mode) 3. move the cursor (used in vi command mode) 1. use the up and down arrow keys 2. in command mode: h to the left, j Down, k to the top, and l 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 the n-character dd starting from the cursor // delete the ndd of the current row // delete the n rows including the current row u // cancel the previous operation U // cancel 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 the vpser string n from the cursor // search for the previous search action N // search for the previous search action 6. jump to the specified line (used in vi command mode) n + // jump n rows n-// jump n rows nG // jump to n rows G // jump to the bottom of the file 7. set the line number (vi command) mode): set nu // Display row number: set nonu // undisplay row number 8, copy and paste (used in vi command mode) yy // copy the current row to the cache, you can also use "ayy replication," a as the buffer, and a can also be replaced with any letter from a to z to complete multiple replication tasks. Nyy // Copy the n rows of the current row to the buffer. you can also use "anyy replication," a is the buffer, and a can also 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. 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 use "ap" for pasting. P // paste the content in the clipboard before the cursor. if you use the custom buffer above, we recommend that you use "aP for pasting. 9. replace (used in vi command mode): s/old/new // replace the first old in the line with new: s/old/new/g // replace all old: n in the row with new, m s/old/new/g // use new to replace all the old values in the n to m rows: % s/old/new/g // replace all the old 10 files in the current file with new. 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 appears in the text file under win in linux. Summary: vi has many commands, but as long as you work diligently, I believe that you will be very familiar with them quickly, and will also bring higher efficiency to your work or study. If you do not know what mode you are in, press the Esc key twice to return to the command mode. a last note will be given: pay attention to case sensitivity !!!
Related Article

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.