Method 1 of multiline deletion and replication in VI: single row deletion,: 1 (row to be deleted) d multiline deletion,: 1, 10 days Method 2: row where the cursor is located, dd: place the cursor in N rows below the row. Ndd Method 1: place the cursor in row 6th, input: 2yy place the cursor in row 9th, and input: p this method is suitable for copying multiple rows in a small number of lines of text VI delete and copy Method 1: Single row delete,: 1 (to be deleted) d multiple rows delete,: 1, 10 days Method 2: the row where the cursor is located, and the dd cursor is located in N rows below the row. Ndd Method 1: place the cursor in row 6th, input: 2yy place the cursor in row 9th, and input: p this method is suitable for copying a small number of lines of text. copy two rows of data under 6th rows (inclusive) and put them under 9th rows. Method 2: in command line mode, enter 6, 9 co 12 to copy the content between 6th rows and 9th rows to the end of 12th rows. Method 3: you can use tags to move the cursor to the starting line instead of reading a large number of rows or copying a large number of rows. enter ma to move the cursor to the end line, and input mb to move the cursor to the paste line, enter mc and then: 'A, 'B Co' c. change co to m to cut the multi-line deletion. you can use the following command: 5, 9 de VIM common command 1) the cursor command k, j, h, l --- move the cursor from top to bottom. Although the four cursor keys on the right of the keyboard can be used in Linux, it is very useful to remember these four commands, that is, nG ---- n, the position of the right hand on the keyboard, is the number of rows. this command immediately redirects the cursor to the specified row. Ctrl + G ----- number of rows and columns at the cursor position report w, B ------ let the cursor forward or backward skip a word 2) Edit command I, a, r ------- before the cursor, insert the character command above (I = insert, a = append, r = replace) cw, dw ------ Change (replace) /command for deleting the word at the cursor position (c = change, d = delete) x, d $, dd ----- delete a character, all the characters from the cursor position to the end of the line, and the entire line of command 3) Find the Command/string ,? String ----- command to find the corresponding string from the cursor to the back/forward 4) copy the copy command yy, p ----- command FAQs and application tips for copying a row to the clipboard/getting the content from the clipboard 1) read the content in/etc/passwd in a new file and retrieve the vi file in the username section: r/etc/passwd read/etc/passwd: % s /:. * // g delete all parts after the username in/etc/passwd from the colon to the end of the line: 3r/etc/passwd this is to read the file content after the specified row number. Another method is to delete all the empty lines in the file and comment lines starting with # cat squid. conf. default | grep-v '^ $' | grep-v '^ #' 2) after opening a file and editing it, the logged-on user has no write permission for the file, you cannot save the vi file: w/tmp/1. since you cannot save the disk, you do not want to give up all the modifications you have made, First temporarily save to/tmp/1: 20, 59 w/tmp/1 or simply save the content between 20th and 59 rows into a file/tmp/1 3) use VI to edit a file, however, you need to delete the contents of a large segment. vi file Ctrl + G move the cursor to the row to be deleted, press ctrl + G to display the row number, and then press Ctrl + G at the end.: 23,104 5d if the two row numbers are 23 and 1045, you can delete all the contents of the two rows. you can also use ma in the start and end lines, mark the mb command and use: 'A, 'bd delete. 4) add a string vi file at the beginning or end of the line to the entire file or several lines: 3, $ s/^/some string/insert some string before the beginning of the first line to the last line of the file: % s/$/some string/g add some string: % s/string1/string2/g at the end of each row of the entire file replace string1 with string2 in the entire file: 3, 7 s/string1/ String2/replace string1 in the third to seventh rows of the file into string2Note: s is substitute, % represents all rows, g represents global5) edit two files at the same time, copy and paste the text vi file1 file2 yy in two files, open two files at the same time, copy the row where the cursor of file 1 is located: n switch to file 2 (n = next) p paste the copied line at the cursor position of file 2: N switch back to file 1 6) replace the path in the file: % s #/usr/bin # g replace all the paths/usr/bin in the file with/bin or use: % s // usr/bin // bin/g indicates '/' is a single character '/' 7 with a symbol before) if you want to annotate a multi-line program with a multi-line comment with vi, a stupid way is to insert #, and then use j to jump to the next line. command. Repeat the previous command. If you want to comment hundreds of lines, this method may be too stupid. A clever method is:., + 499 s/^/#/g. to insert the first line of the full text, run the following command: % s/^/#/g.
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.