Vim Common commands

Source: Internet
Author: User

1) Cursor command

K,j,h,l---up and down around the cursor Movement command, although you can use the keyboard to the right of the four cursor keys, 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 where the cursor is located  w,b------make the cursor skip a word forward or backward  2) Edit the command  i,a,r-------before the cursor, after the insertion 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 a character, All the characters at the end of the line at the cursor, and the entire line of command  3) find the command  /string,? string-----Copy the Copy command  yy,p from the command  4 to find the appropriate string from the cursor location)----- To copy a line to the Clipboard/remove the contents of the Clipboard frequently asked questions and application tips  1) in a new file read the contents of/etc/passwd, remove the user name part  vi file :r/etc/passwd In the open file, the cursor is read in/etc/passwd :%s/:.*//g delete/etc/passwd after 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 blank lines in the file and comment lines starting with #   #cat Squid.conf.default | Grep-v ' ^$ ' | Grep-v ' ^# ' 2) after opening a file editing only to know that the user logged on to the file does not write rights, can not save the  vi FILE :W/TMP/1 since cannot disk, do not want to give up all the changes made, first temporarily saved to/tmp/1  : 20,59W/TMP/1 or simply save the contents of the 20th to 59th row into a file/tmp/1 3) edit a file with VI, but need to delete the large segment of the content  vi file ctrl+g Move the cursor to the line that you want to delete, press Ctrl+g to display the line number, and then press ctrl+g.&nbsp at the end:23,1045D assumes that two times the line number is 23 and 1045, then the contents of these can be completely deleted or in the beginning and end of the two lines with the MA,MB command marked with: ' A, ' bd delete.  4) add some strings to the beginning or end of a line in the entire file or lines  vi  :3, $s/^/some string/insert some string :%s/$/some string/g in the first line of the file until the beginning of the last line, add some string:%s/at the end of each line of the file String1/string2/g replaces string1 into string2 :3,7s/string1/string2/in the entire file, replacing only string1 string2note in the third to seventh line of the file: s for substitute,% all rows, G for GLOBAL5) to edit two files simultaneously, copy the clip text in two files  vi file1 file2 yy Open two files at the same time, copy the row at the cursor where the 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 the file 1 6) replace the path in the file:%s#/usr/bin#/bin#g switch all paths in the file/usr/bin to/bin   or using  :%s//usr/bin//bin/g to indicate '/' is a true single character '/'  7 with a '/' before using the VI multiline Note 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:  :.,+499 s/^/#/g  if you want to insert the full-Text header, the following commands are available:%s/^/#/g

Vim Common commands

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.