Usage of VI under Linux

xiaoxiao2021-03-06  39

Usage of VI under Linux

Summary

Basic Note Guide for VI under Linux (2005-01-09 20:08:05)

By lanf, source: http://tech.ccidnet.com/pub/Article/c302_a200213_p1.html

Author: Linux a treasure trove of knowledge, Basic command ---- 1 The cursor command k, j, h, l - up, down, left, right cursor movement command. Although you can use the four cursor keys on the right of the keyboard in Linux, remember that these four commands are still very useful. These four keys are the basic location of the right hand placed on the keyboard. Ng - Jump command. n is the number of rows, which immediately jumps to the specified line. Ctrl g - the number of rows and column numbers in the location of the cursor. W, b - make the cursor forward or back a word. ---- 2. Edit Commands I, A, R - Before, after the cursor, insert the character command (i = I = insert, a = append, r = replace). CW, DW - Change (replace) / Delete the command command (C = Change, D = Delete) where the cursor is located. X, D $, DD - Delete a character, delete all characters where the cursor is located, and deletes the commands. ---- 3. Find commands --- / string,? String - The command of the corresponding string is found from the cursor or forward the corresponding string. ---- 4. Copy the copy command ---- YY, P - copies a line to the clipboard or take out the contents of the clipboard. Second, common problems and application skills ---- 1. Remove the username section in a new file in a new file. ---- vi file ----: R / etc / passwd Reads / etc / passwd in the open file file in the cursor in the cursor in the cursor ,--:% S /: The neutral username begins with the colon until all parts of the end. ---- You can also read file contents after the specified line number, such as using the command ": 3r / etc / passwd" from the third line of the new file to start reading / etc / passwd. ---- We can also use the following methods to delete all the blank lines in the file and the notes starting with #. - #cat squid.conf.default | grep -v '^ $' | grep -v '^ #' ---- 2. After opening a file editor, you know that the user doesn't have written, you can't store the file, you need to save your modifications into the temporary file. ---- vi file ----: W / TMP / 1 Save all modifications, you can also modify some of them to temporary files, such as the contents of the contents between the 20th to 59 lines File / TMP / 1, we can type the following command. ---- VI File ------------------------------------------ Edit a file with VI, but you need to delete the contents of the large segment. ---- First, use the editorial command "Vifile" to open the file, then move the cursor to the row you need to delete, press Ctrl g to display the line number, and then press Ctrl G at the end and display the line number ending. ---------------------------------------------------------------------------------------------------- ": 'A,' bd" command deletes. ---- 4. Add some strings to the entire patriarchal or a few rows of lines or rows. ---- VI File ------: 3, $ s / ^ / some string / in the first line of the file to the final line of the first line of "Some String". ----:% s / $ / some string / g adds "some string" at the end of each line of the entire file. ----:% S / STRING1 / STRING2 / G Replace "String1" into "String2" throughout the file. ----: 3, 7S / String1 / String2 / Only Replace the "String1" in line 3 to the 7th line in the file into "string2". ---- Note: where S is substitude,% means all rows, g represents Global.

转载请注明原文地址:https://www.9cbs.com/read-64855.html

New Post(0)