vim tips Author: camry.wu@gmail.com I am a fan of vim, use for a long time, have some of their own feelings, and dug around for some other people feel more useful tips for vim fans, put it down in here. I hope that I will take this kind of money, I will have ancient words that should be thrown into the jade. I will introduce Vim. VI is a very common text editor under UNIX / Linux, most of the machines. VI There are various variants that are commonly used in different machines. There is also a more wide use of VIM. Vim is the abbreviation of VI Improved, indicating better Vi. I personally think it is a very good editor. (In order to avoid Emacs fans, it will not be said to be the best). It is also recommended to see if it is not used. Of course, VIM is very convenient to write text files, such as writing programs, HTML documents, etc., but cannot be used to write Word. Documentation. About Vim installation, basic use methods, etc., you can search for many, you are not here, if you are interested in Vim, then look at this (Chinese document): http://vcd.gro.clinux .org / This article says it is more useful, more common commands. If you can use these commands, you will find that the editing file is very comfortable. Description: The following example indicates that XXX is input to XXX in command mode and enter the following In the example: XXX indicates that the command is entered in the extended mode and enter the command in parentheses indicates the related command. The command entered in edit mode or visual mode will be indicated. 1. Find / xxx (? Xxx) Search in the entire document, search the XXX string, / indicates the down look, indicating that the up lookup. The XXX can be a regular expression, and there is not much to say about the regular shape. Generally, it is case sensitive, to think Not case sensitive, then enter: set ignorecase Find later, enter N to find the next match, enter the N anti-direction lookup. * () When the cursor is on a word, enter this command indicating Find a word that matches the word (on). Similarly, enter N to find the next match, enter the N anti-direction lookup. G * (g #) This command is similar to the upper command, but only It does not completely match the words where the cursor is located, but matches all strings containing the word. GD This command finds the words match the word where the cursor is located, and the cursor stays in the document in the non-invisuit section of the document. Where the word.% This command finds the hinges matching the cursor, including () [] {} f (f) x This command indicates that the cursor is in the line of the cursor, find the first right (left) party X character. After finding: input;
Indicates that the input is continued, indicating that the reverse direction looks for 2. Fast moving cursor in VI, mobile cursor and editing are two things, because distinguishing, it can be easily positioned and edited. A little moving cursor is very useful. W (e) moves the cursor to the next word. B Move the cursor to the previous word. 0 Move the cursor to the beginning of the Bank. ^ Move the cursor to the most beginning of the Bank. The cursor is at the end of the Bank. H moves the cursor to the first line of the screen. M moves the cursor to the middle line of the screen. L Move the cursor to the screen. The GG moves the cursor to the document header. G move the cursor to the document tail row. CF ( That is, the CTRL key is pressed with the F button) This command is Page Down. CB (ie, the Ctrl key is pressed with the B key, then the same) this command is Page Up. '' This command is quite useful, it moves the cursor to the previous one After the tag, such as using GD, *, etc., then enter this command, return to the last stay. '. This command is quite good, it moves the cursor to the last modification line. `
This command is quite powerful, it moves the cursor to the last modification point. 3. Copy, delete and paste in the VI Y Representation copy, P denotes the deletion, the P is pasted. Where the copy and deletion is combined with the cursor movement command, Look at a few examples. YW indicates that the copy from the current cursor to the word of the cursor. DW indicates the content that deletes the word ending from the current cursor to the cursor. Y0 means copying from the current cursor to the current cursor to the cursor . D0 means that deletes the content from the current cursor to the cursor. Y $ represents the content from the current cursor to the tail of the cursor. D $ represents the content of the tail from the current cursor to the cursor. Yfa represents the copy from the current The cursor to the content between the first A character behind the cursor. DFA indicates the content between the first A character from the current cursor to the cursor. Special place: YY indicates that the cursor is located. DD indicates the deletion of the cursor. Row. D represents the content deleted from the current cursor to the tail of the cursor. About the copy, delete, and paste the complex usage related to the register, you can query it yourself .4 .4. Digital and command combination in the VI often expressed this Command, if there is a line number positioning in the beginning of the extended mode. For example, 5FX indicates the 5th X character after the cursor. 5W (e) move the cursor to the lower five words. 5YY indicates that the cursor is below 5 rows. 5DD Delete 5 rows below the cursor. Y2FA represents the content between the copy from the current cursor to the second A character behind the cursor.: 12,24y indicates the content between the 12th line to the 24th line.: 12, y Represents copy Chapter 12 to the content between the cursor is located.: 24y indicates the content between the copies of the cursor to the 24th line. Delete similar .5. Quick input characters in VI, do not ask you to enter each character, can There are many ways to enter some characters quickly. Students using Linux / Unix must have an experience, When you enter a command on the command, you will automatically press the TAB system to make the remaining characters, if you have multiple matches, you will print it. This is the famous command complement (in fact, there are also Windows. File Name Rifting Function). There are many string tuning commands in VI. It is very convenient. CP (CN) In editing mode, enter a few characters before entering this command, the VI starts to the top (below) Search start with it. Words and refine, constantly enter this command loop. This command matches all files opened in this VIM program. CXL In editing mode, this command quickly complements the whole line content, but only in this Match in the document that appears in the window. CXF In editing mode, this command represents the file name. If you enter: / usr / local / TOM, enter this command before it will match: / usr / local / Tomcat / abbr is abbreviated. This is a macro action that can be used instead of another string in edit mode. For example, writing system.out.println, which is written in the Java file, which is very trouble, so you should use abbreviation to reduce knock Word. Can do this::
Abbrint System.out.Println After entering SPRT, then enter the other non-alphabetic symbol, which will automatically expand to system. out.println6. Replacement replacement is the strength of VI, because you can match the string with a regular expression. Several examples are provided.: S / AA / BB / G replace all AA in the row of the cursor in the AA string to BB: S / /
This is convenient. These configurations can be written in advance to ~ / .vimrc (WINDOWS $ VIM / _VIMRC), do not write the previous colon when writing.: NMAP
Enter this command to move a Tab 5 after the cursor.: 12,24> This command moves 12 lines to 14 lines of data to the right a Tab.: 12,24 >> This command will 12 line to 14 lines The data moves two Tabs to the right. So how do I define the size of the Tab? Some people are willing to use 8 empty graces, some people use 4, some use 2. Some people hope that Tab is completely replaced by spaces, and some people I hope that Tab is Tab. It doesn't matter, Vim can help you. The following settings are generally written to the configuration file, which is reluctant to be old. The settings are automatically indented to 4 spaces, of course, automatic indentation first. : set STS = 4 Set SoftTabStop is 4. After entering Tab, you jump 4.: set tabstop = 4 The actual Tab is 4 spaces, not the default 8.: SET ExpandTab After entering Tab, Vim fills this tab.10 with the right space. AutoCMD is very powerful, you can use this command to apply different configurations for different file formats; you can automatically add copyright statements when new files. These orders are generally In the configuration files such as ~ / .vimrc. Because he is very powerful, I can't give a very specific instructions, can only mention a few examples, please see help.: AutoCMD! Delete all previous automatic commands. AutoCMD Filety Java Source ~ / .vim / files / java source ~ / .vim / files / jAVA SOURCE ~ / .VIM / FILES / JCOMMENTER.VIM The above two commands let me apply the two configuration files mentioned later when opening the Java file. AutoCMD BUFNEWFILE * .JAVA 0R ~ / .VIM / Files / Skeletons / Java.skel All This command allows me to automatically join the Java.Skel file when new Java files. AutoCMD bufnewfile * .java Normal GNP or above this command I automatically run GN when I build Java files. p Command, this command makes some specialization processing, such as replacing __date__ in the new Java file with what today's date .11. Common script You can find a lot of scripts in Vim.sf.net, these scripts are often There is no unexpected role. I often use: JCommenter.vim automatically joins the javadoc style note. JBrowser.vim resource browsing. C, C , etc. can be used in TLIST, such as Checkstyle.vim can check you The programming style, JAD.VIM can directly confine .class files, etc.12. Common configuration in ~ / .vimrc configuration file You often need some personalized configuration. For some macro definitions, some autocmd definitions, etc. . Such as: SET SUFFIXES =