Multi-line deletion and replication in VI

Source: Internet
Author: User

multi-line deletion and replication in VI: Single-line deletion:1(Row to delete) d multi-line Delete,:1, 10d method Two: The line of the cursor, the DD cursor row of n rows, Ndd Method 1: The cursor is placed on line 6th, input: 2YY cursor to line 9th, enter: P This method is suitable for copying a small amount of text, the line 6th row (including) the following 2 rows of data, placed below the 9th line. Method 2: Enter the command line mode6,9Co ACopy the contents of lines 6th through 9th to the following line 12th. Method 3: Sometimes you do not want to struggle to see how many rows or to copy a large number of lines, you can use the label instead of the cursor move to the starting line, enter the MA cursor to the end line, enter the MB cursor to paste the line, enter the MC and then:'A,'B Co'c Change the co into m and cut it.To delete multiple lines, you can use:5,9devim Common Commands Common command1) cursor Command k,j,h,l---The cursor moves up and down the command, although you can use the four cursor keys to the right of the keyboard in Linux, but remember that these four commands are also very useful, that is, the right hand on the keyboard placed on the location part ng----N is the number of rows, and the command immediately causes the cursor to jump to the specified line. Ctrl+g-----Number of rows and columns at the cursor location report W,b------make the cursor skip forward or backward through a word2) Edit Command I,a,r-------before the cursor, after the Insert character command (i=insert,a=append,r=replace) CW,DWcommand to------change (displace)/delete the word where the cursor is located (c=change,d=Delete) X,d$,dd-----Delete one character, all characters at the end of the cursor, and the entire line of commands3) Find command/string, ?string-----Backward from the cursor positioncommand to find the appropriate string forward4Copy copy command yy,p-----Copy a row to the Clipboard/commands to remove content from Clipboard FAQ and application Tips1) Read/etc/in a new filepasswd the contents, remove the user name Part VI file:r/ETC/PASSWD reads the cursor in the file that opens/etc/passwd:%s/:.*//g Delete all parts of the/etc/passwd after the user name, starting with the colon until the end of the line: 3r/etc/passwd This is to read the file contents after the specified line number another way to delete all empty lines in the file and comment lines starting with # #cat squid.conf.default| Grep-v'^$'| Grep-v'^#' 2After you open a file to edit the user does not know the login to the file does not write rights, can not save the VI file:w/tmp/1Since can not save the disk, do not want to give up all the changes made, first temporarily saved to/tmp/1 : -, 59w/tmp/1Or just save the contents of the 20th to 59th line as a file/tmp/13edit a file with VI, but need to delete the large segment of the content VI file Ctrl+G move the cursor to the line you want to delete, press Ctrl+g to display the line number, and then press CTRL + at the endG.: at, 1045D assumes that two times the line number is 23 and 1045, then the contents of these rooms are all deleted can also be used in the beginning and end of the two lines with the MA,MB command marked with:'A,'BD Delete.4Add some string vi file at the beginning or the end of the line in the whole or a few lines:3, $s/^/somestring/Insert some before the start of the first line of the file to the beginning of the last linestring :%s/$/somestring/g add some at the end of each line of the entire filestring :%s/string1/string2/g replace string1 into string2 throughout the file:3, 7s/string1/string2/replace only string1 in line third to seventh in the file with string2 note:s as substitute,%represents all rows, and G represents the global5edit two files simultaneously, copy the clip text in two files vi file1 file2 yy open two files at the same time, copy the line at the cursor where the file 1 is located: N Switch to file 2 (n=next) Paste the copied line at the cursor of File 2: N switches back to file 16) to replace the path in the file:%s#/usr/bin#/bin#g all the paths in the file/usr/bin replace thebin or by:%s//Usr/bin//bin/g in '/' before the symbol '/' is a true single character '/'7with the VI multiline comment if you want to annotate a multiline program, a stupid way is to insert # and then jump to the next line with J. command, repeat the last command. If you want to comment on line hundreds of, this method is probably too stupid. One clever way to do this is:.,+499S/^/#/g

Multi-line Delete and copy (go) in VI

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.