I: Introduction: vi command can be said to be commanded by the most common editing file in the UNIX / Linux world, many people don't like VI because of its numerous command sets, but we only need to master basic commands and then use it flexibly. I believe you will be like me. This article is intended to have some most common commands and some advanced applications that are summarized in summary. 2: Basic order introduction: 1) Cursor command k, j, h, l --- up and down left and right cursor mobile commands, although you can use the four cursor keys on the right side of the keyboard in Linux, but remember these four commands Very useful, that is, the right hand placed on the keyboard Ng ---- n is the number of rows, which immediately jumps to the specified line immediately.
Ctrl G ----- The number of rows and column numbers in the location of the cursor are W, B ------ make the cursor forward or back a word 2) Edit Command I, A, R --- ---- Insert the character command (i = I = insert, a = append, r = replace) CW, DW ------ Change (replacement) / delete the word where the cursor is located (c = change, d = delete) x, d $, DD ----- Delete a character, all characters in the cursor to the end of the row, and the whole line command 3) Find commands / string,? string - --- Command 4 of the corresponding string from the cursor / forward to the corresponding string of the corresponding string 4) Copy the copy command yy, p ----- Copy a line to the clipboard / remove the content of the content in the clipboard three: FAQ and Application Skill 1) Read / etc / passwd in a new file, remove the username section VI File: R / etc / passwd In the open file file, the cursor is read / etc / passwd:% S /: * // g Delete the username from the username from the Username until all parts of the end until the end of the line: 3R / etc / passwd This is the read file content after the specified line number is read in another method to delete the file All blank lines and commented in the #CAT Squid.conf.default | grep -v '^ $' | grep -v '^ #' 2) Know that the user knows the file after opening a file editor No write rights, can not store vi file: w / tmp / 1 is not allowed to save, do not want to give up all the modifications made, first temporarily save / TMP / 1: 20, 59w / tmp / 1 or only put you 20 to 59 The content storage between the lines / TMP / 1 3) Edit a file with the VI, but you need to delete the content vi file ctrl g of the large segment VI File Ctrl G to move the cursor to the row that needs to be removed. No., then press CTRL G at the end.: 23, 1045d assumes that the line number is 23 and 1045, the content is completely removed. You can also use the MA, the MB command mark after starting and ending in both lines: 'a,' bd deletion. 4) Add some string VI File: 3 in the first file or in a few rows. $ S / ^ / Some String / Insert Some String:% S / $ / SOME STRING / G in the first row of the files:% s / string1 / String2 / G Replace String1 in the entire file String2: 3, 7s / string1 / string2 / only in the third to seven lines in the file, the string2 Note: s Substitution,% means all rows, g represents Global 5) Simultaneously edit two files, copy the clippers vi file1 file2 yy in two files At the same time, open two files, copy the line in the cursor of the file 1: n Switch to file 2 (n =