Seven habits of effective editing BRM MOOLENAAR If you are used to knock down the text, write programs or HTML, then effectively use a good editor to save you a lot of time. The guidance and tips in this article will help you work faster, fewer mistakes. The open source text editor VIM (VI Improved) describes the idea of effective editing, but these ideas apply to other editors. The choice of appropriate editor is just a first step in effectively editing, which will dominate which editor better discussion, this will not be mentioned. If you don't know which editor should use, or you are not very satisfied now, try vim; you will not be disappointed. The first part: Editing a file fast positioning in the editor is spending in reading, checking, and looking for a place to edit, rather than inserting a new text or modifying. Constant positioning in the file is often done, so it is best to learn how to make it quickly. You often search for some texts in your document. Or find rows that contain specific words or phrases. You can of course use search command / pattern, but there is a smarter method: * If you see a specific word, you want to see if you have the same word, you can use the * command. It will search for the words referred to in the cursor. * If the 'incsearch' option is set, Vim will display the results of the search when you are entering the search mode (rather than waiting until you have a carriage return). This enables you to find spelling errors faster. * If the 'HLSearch' option is set, VIM will use the yellow background to highlight the search results. You can see the results of the search. Apply all references to variables in program code. You can see all the search results without even need to move your mouse. For structured documents, the quick positioning method is more. Vim provides special commands for C processes (and C , Java, etc.): * Using% can jump from the beginning bracket to the corresponding shutdown parentheses. Or jump from `` #if '' to the corresponding `` #ndif ''. In fact,% can complete the jump between many corresponding items. Can be used to check if the IF () and {} structure balance. * Use [{can jump back to the segment starting `` `` `` `` ``. * Use GB to jump from a reference to a certain variable to its local statement. The method of positioning is certainly not these. The key is that you need to know that there are these orders. You may say that it is impossible to learn all commands - Vim has hundreds of positioning commands, some are simple, some are very smart - this takes a few weeks. However, you don't have to do this; you just need to understand your own editing characteristics, then master the relevant positioning commands. Three basic steps can be taken: 1. Pay attention to those repeated operations when you edit. 2. Find the editorial command that can make these operations quickly. Read the documentation, ask friends, or see how other people do. 3. Exercise and know skilled. Let's explain the following example: 1. You find that you want to find the function definition when you write the C program. You are currently using the * command to search for the function name, but the resulting is often a reference to the function rather than the function definition. You feel that there will be a better way. 2. After reading a quick reference, you find a description of the positioning mark, inside how to locate the function definition, this is what you have to find! 3. You tried to generate a tag file and use the VIM's own CTAGS program. You have learned to use the ctrl-] command and found that this saves a lot. For more convenience, you have added a few lines in Makefile to automatically generate tag files.
When you use the above three steps, there are some places to pay attention to: * `` I just want to complete the task, don't want to read those documents to find new commands. ''. If you really think so, you will stay in the calculated stone era. Some people write everything with NOTEPAD, but never understand why others can always use his half of the time. * Don't be too much. If you are always a small matter, you have to find a perfect order, you can't concentrate on your task you have to complete. Just find out how much time spent, then use the relevant command until you are skilled. This will then focus on your documentation. The following sections give the operations encountered by most people. You use three basic steps in actual work. Don't knock two words we use are limited. It is not only a limited number of phrases and sentences. This is even more like program. Obviously, you don't want to knock the same thing twice. You often want to replace a word into another. If you are a full file replace, you can use the: S (Substitution) command. If only a few locations need to be replaced, a quick way is to use the * command to find the next word, use CW to replace it. Then knock n to find the next word, reuse. Repeat the CW command. The command repeats the last change. The change here is insert, deleted, or replaced. It is an extremely powerful mechanism that can be repeatedly operated. If you use it well, then most of your editorial work may only be knocked down. Things. Be careful not to make other changes between twice, because this will change the operation you want to repeat. If you do need this, you can use the m command to remember the location you want to modify, and wait back to modify it after the repeated operation is completed. Some function names and variable names may be difficult to knock. Can you enter the `` xpmcreatepixmapfromData ''? Vim automatic complement mechanism can save you a lot of things. It looks at the file you are editing and #include file, you can only type `` xpmcr '', then use the ctrl-n command to make VIM to make it `` xpmcreatepixmapfromData ''. This not only saves the input time and reduces the input error. If you have the same phrase or sentence to enter multiple times, there is a simpler way. VIM can record macros. Use the QA command to record macros in the 'A' register. Then enter the editing command normally, and finally use Q to exit the recording state. If you want to repeat the recorded command, just execute the @a command. Vim has a total of 26 macro registers. Various operations can be recorded using a macro recording feature, not limited to insertion operations. If you want to repeat something, you may wish to try. It should be noted that the recorded command will be repeatedly executed. Simple repetitive macro operations when positioning may not be the result you want. For example, for a word, you may need to move down to 4 characters left, and you may have 5 characters left in the next place. So you must be positioned to the appropriate position and repeat the macro operation. It is difficult if you have to repeat the commands, which will be difficult to knock in it. At this point you can write a script or macro. This is often used to establish a code template; for example, a function head. You can do more smart and smart. Children will often go wrong when they will change the editor. Unmanned free. The key is to quickly discover and correct it. The editor should provide this support, but you have to tell it what is wrong. You may often repeat the same mistake, your finger is not doing you want it. You can use an abbreviation for fixing. Here are some examples: *: abbross across *: abbross across *: Abbr HTE The word will be automatically corrected when editing. The same mechanism can also be used to abbreviate long words. It is especially suitable for inputs that you feel very difficult, it can avoid mistakes.
For example: *: abbr pn pinguin *: Abbr Ms Mandrake Software But sometimes you want is those abbreviations, such as inserting `` ms ''. Therefore, it is best to use those words that do not appear in the article. Vim provides a very clever highlighted mechanism, generally used for the program's syntax highlight, but it can also be used to check the error. Syntax highlights use color display comments. This is not a particularly important feature, but once it is used up, it will find that this is actually very useful. You can quickly find text that is not highlighted as a comment (probably because I forgot to knock the horses). You can also find some code that is incorrect as a comment (probably because I forget the `` * / ''). These errors are difficult to discover in black and white, and a lot of debugging time is wasted. The syntax is highlighted can also be used to find mounting parentheses. A unpredictted ``) '' will be logified by bright red background. You can use% commands them to match, and then insert the `` ('' or ``) '' into the right position. Another common mistake is also very easy to find, such as a `` #include
Let's work together to edit files. The e-mail program can send and receive messages. The operating system can run the program. Each program has its own task and should be done. If you can work together, you will achieve a very powerful function. For a simple example: Select the structured text in a list and sort it:! Sort. This will use external command `` sort '' to filter files. Easy? Sorting features can be added to the compiler. But look at `` man sort '', know it has a lot of options. It may use an extremely delicate sort algorithm. Do you still plan to add it to your editor? What's more, there are many other filters. The editor may become large. An embarrassment of UNIX spirit is to provide independent programs, each doing their own tasks, then combine to complete larger tasks. Unfortunately, many editors do not work well with other programs, for example, you can't package Netscape's mail editor to replace it with another editor. This way you can only use the unhappy program. Another trend is to provide all the features in the editor, Emacs is a representative (someone says Emacs is actually an operating system, just can be used to edit files). Vim tries to integrate with other programs, but this needs to be struggled. At present, VIM can already be an editor of MS-Developer Studio and SNIFF. Some e-mail programs (such as MUTT) also support external editors. And Sun Workshop integration is in progress. In general, this area has yet to be improved. In the future, we will have a system greater than its partial part. Text Structured You may often encounter texts that have some structures that may be with the structure supported by those existing commands. So you have to use those underlying `` bricks '' to create your own macro and script. The description herein is the more complicated things. There is a simple way to speed up editing - compile - modify this loop. Vim provides: make command for compiling, and gets an error output to correct you to an error. If you use another compiler, then the error cannot be obtained by Vim. If you don't want yourself, you can modify the 'ErrorMMAT' option. Tell the Vim error what is like, and how to get the file name and line number. It supports complex GCC error messages, so other compilers should also be supported. Sometimes a new file type only needs to set a few options or write some macros. For example, in order to jump in the MAN manual, you can write a macro to get the word under the cursor, clear the buffer, and then read the new MAN manual. This is a simple and efficient reference method. With three basic steps, you can process various structured files more effectively. Just think about what you want to take on the file, then find the corresponding command to use it. It's so simple, you just have to do it. Part III: Worship to develop habits to learn to drive. Is this why you only ride a bicycle? Of course, you will find that you have to take the time to get the required technology. Text editing is no exception. You need to learn new commands and use it until you become habits. On the other hand, you should not try to learn each command provided by the editor. This is a complete waste time. Most people only need to learn 10% to 20% of orders. But the commands needed for each person are different. You need to continue to learn and find out that you can complete it. If you only do one action, and you will not do any more in the future, then you don't need to optimize. If you find that you repeat several times in the past hour, you need to check the manual to see if it can be done faster. Or write a macro to do it. If it is a small task, such as alignment of a class of text, you need to read the newsgroup or see if there is anyone on the Internet already solved the same problem.