VIM experience

xiaoxiao2021-03-06  60

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 / / / bb / g to display all the rows where the cursor is located AA replaces BB, only replacing the AA:% S / AA / BB / G replace all AA in the AA string in the document to BB: 12, 23S / AA / BB / G will be from 12 lines All AAs included in the AA string are replaced with the AA of the AA-containing AA to join the # character:% s = * $ == will be owned by the 12 lines to 23 rows. The extra space deletion: g / ^ / s * $ / d Remove all space lines that do not contain characters (spaces). 7. Multi-file editing Opens a lot of files in a VIM program to edit is very convenient : SP (: vsp) file name Vim will split a horizontal (vertical) window and open a new file in this window. Starting from VIM6.0, the file name can be a directory name, so that Vim will Turn this directory and display the file list, press Enter on the file name to open the file in this window, if you enter O, open the file in a new window, enter? You can see help information.: E File name Vim Open a new file in the original window, if the old file edited, save it. CWW Vim What should I do with several windows? Enter this command to locate the cursor cycle into each window.: Ls This command View this VIM program How many files have been opened, the following data is displayed at the bottom of the screen: 1 % a "Usevim.html" line 162 2 # "xxxxx.html" line 0 where: 1 indicates the open file number, this serial number is useful.% represent the file code,% means the current edited file, # means last time Edited File "Usevim.html" represents the file name. Line 162 represents the cursor position.: B serial number (code) This command opens the file that specifies the serial number (code) in this window, where the serial number (code) is: ls command See it.: Set diff This command can be used to compare two files, you can use: vsp filename command to open another file, then enter this command in each file window, you can see the effect. 8. Macro replacement VI Not only can I use abbr to replace text, but also the macro definition of commands. Some commands are very powerful, so I define them to -

This is convenient. These configurations can be written in advance to ~ / .vimrc (WINDOWS $ VIM / _VIMRC), do not write the previous colon when writing.: NMAP : nohls cancellation Highlights of the search string: NMAP W command mode Transfer cursor to different windows: IMAP Enter mode Run : NMAP :% s = * $ == Delete all the ends of the end of the end of the end of the row.: IMAP : in Java: (Note, why Java is in Java, because the following definition is not affordable Role, here will say how to achieve this): NMAP : comp javac : MAK -D.% This command compiles the Java file with Javac, which will automatically position the cursor to the error point. But This requires a Javac.vim file under $ VIM / Compiler, only two lines in javac.vim: setLocal makeprg = javac setlocal error errormat =% a% F:% L: /% M,% - Z% P ^ ,% - c%.% #: Nmap : comp around : mak compiling Java files with ANT, which automatically locates the cursor to the error point. In general, after installing VIM With the Compiler / Ant.vim file, this command can be used directly. But you need to have a build.xml file in the current directory, of course, Ant must be installed.: NMAP : CL This command is used for View all compilation errors.: IMAP : NMAP : CC This command is used to view the current compilation error.: IMAP : NMAP : CN This command is used for Jump to the next error position.: IMAP : NMAP : CP This command is used to jump to the previous error position.: IMAP : NMAP : javabrowser This command is used to cut a new window on the left side, the content inside is the Java resource tree, including the class, the members variables and members of the class, the class, and the membership method. It seems like JCREATOR performance. Enter your help in this window? Hey, it is very easy to use, but you need CTAGS support.: Imap 9. Tab Tab is tab, Out of the section is because this thing is really useful. << Enter this command, move a tab in the row in the cursor to the left. >> Enter this command to move a Tab. 5 >>

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 =

转载请注明原文地址:https://www.9cbs.com/read-113922.html

New Post(0)