Operation in Vim

Source: Internet
Author: User

Multi-line Delete and copy method one: Single row Delete,: 1 (row to delete) d multi-row deletion,: 1,10d method Two: The cursor line, DD cursor line of n rows, Ndd Method 1: The cursor is placed on line 6th, input: 2YY cursor placed on line 9th, input: p This method is suitable for copying a small amount of text, Copy the 2 rows of data below line 6th (including) below line 9th. Method 2: In command-line mode, enter 6,9 Co 12 to copy the contents between lines 6th through 9th to the 12th line. Method 3: Sometimes do not want to struggle to see how many rows or copy a large number of lines, you can use the label instead of the cursor to move to the starting line, enter the MA cursor to the end line, enter the MB cursor to the paste line, enter the MC and then: ' A, ' B Co ' C change the co into m cut to delete multiple lines M common Commands Common command 1) CURSOR Command k,j,h,l---up and down the cursor Movement command, although you can use the keyboard to the right of the four cursor keys in Linux, but remember that these four commands are also very useful, that is, the right hand on the keyboard placement part ng----N is the number of rows, The command immediately causes the cursor to jump to the specified line. Ctrl+g-----The number of rows and columns at the cursor location report W,B------Make the cursor skip forward or backward by one word 2) Edit the command i,a,r-------before the cursor, after the Insert character command (i=insert,a=append,r=replace CW,DW------Change (displace)/delete the command (c=change,d=delete) of the word where the cursor is located x,d$,dd-----Delete one character, all characters at the end of the line at the cursor, and the entire line of command 3) find the command/string,? String-----Command 4 to find the appropriate string from the cursor location) copy copy command yy,p-----Copy a line to the Clipboard/remove the contents of the Clipboard frequently asked questions and application tips 1) Read the contents of/etc/passwd in a new file, Remove the user name section VI file:r/etc/passwd in the open file, the cursor is read in/etc/passwd:%s/:.*//g Delete the/etc/passwd from the beginning of the user name from the colon until all parts of 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 ' ^# ' 2) after opening a file to edit the user is not aware that the logged on the file does notWrite right, can't save VI file:w/TMP/1 since can not disk, do not want to give up all the changes, first temporarily saved to/TMP/1:20,59W/TMP/1 or just the 20th to 59th line between the contents of file/TMP/13) with vi edit a file, But you need to delete the large segment of the content of the VI file ctrl+g the cursor to the line to be deleted, press Ctrl+g to display the line number, and then press ctrl+g at the end.: 23,1045d assume that the two-time line number is 23 and 1045, then the contents of these rooms are completely deleted You can also use the MA,MB command in the start and end lines to mark after: ' A, ' BD delete. 4) Add some string vi File:3 to the beginning or end of the line in the entire file or a few lines, $s/^/some string/insert the first line of the file before the beginning of the last line some String:%s/$/Some string/g add some string at the end of each line of the file:%s/string1/string2/g replace string1 into string2:3,7s/string1/throughout the file string2/only replace string1 in line third to seventh of the file with string2 note:s to substitute,% for all lines, G for global 5) edit two files simultaneously, copy clip text in two files vi file1 file2 yy Open two files at the same time, copy the line where the cursor of file 1 is located: N Switch to File 2 (n=next) p Paste the copied line at the cursor of file 2: N Switch back to file 16) Replace the path in the file:%s#/usr/bin#/bin#g all the paths in the file/usr/ Bin to/bin or with:%s//usr/bin//bin/g in the '/' before the symbol '/' is true single character '/' 7 ' with 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. A clever way is::., +499 s/^/#/g


Ext.: http://blog.csdn.net/wallwind/article/details/7633356

Operation in Vim

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.