Author: gene 15:29 |
Permalink |
Leave (0) |
TRACKBACKS (0) |
Technique
Seven habits for effective editing
Bram Moolenaar
If you have used it to pure text, write programs or html, then use a good editor effectively
The device saves you a lot of time. Guidance and tips in this article will help you work faster, less commit
error.
The open source text editor Vim (VI Improved) describes the idea of effective editing, but these ideas are also
Suitable for other editors. The choice of appropriate editor is just a first step in effect, which editor is more
A good discussion will dominate, this is not mentioned here. If you don't know which editor should be used, or
I don't satisfy now, try Vim; you won't be disappointed.
Part 1: Editing a file
Rapid positioning
Most of the time in the editor is spent on reading, checking, and looking for places that should be edited, not plug.
Enter new text or modify it. 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 make
With search command / pattern, there is a smarter method:
* If you see a specific word, you want to see if there is the same word anywhere, you can use it.
* Command. It will search for the words referred to in the cursor.
* If the 'incsearch' option is set, Vim will be when you are entering the search mode.
Show the results of the search (rather than waiting for you to enter the return). This can make you find a spelling faster
error.
* If the 'HLSearch' option is set, VIM will use the yellow background to highlight the results.
display. You can see the results of the search. Application can display all variables in the program code
Quote. 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 specializes in C processes (and
Special commands for C , Java, etc.):
* Using% can jump from the beginning parentheses to the corresponding shutdown parentheses. Or jump from `` #if ''
The `` #ndif ''. In fact,% can complete the jump between many corresponding items. can
Whether it is used to check if the IF () and {} structures are balanced.
* 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
Will all commands - VIM has hundreds of positioning commands, some are very simple, some are very smart - this needs
A few weeks of learning. However, you don't have to do this; you just need to understand your own editorial character, then master the phase
The locating command is OK.
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 other
How people do it.
3. Exercise and know skilled.
Let us 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 * command-to-write
Digits are searching, but the resulting is often a reference to the function rather than the function definition. You feel certain
Have better ways.
2. After reading a quick reference, you find the instructions on the positioning mark, explain how to position
Function definition, this is exactly 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 are in Makefile
Enter a few lines to automatically generate tag files.
When you use the above three steps, there are a few places that you need to pay:
* `` I just want to complete the task, don't want to read those documents to find new commands. ''. If you are really this
I think, then you will always stay in the calculated stone era. Some people write anything
Notepad, but never understand why others can always use his half of the time to task.
* Don't be too much. If you are always a small matter, you must find a perfect order, you can't concentrate on
You have on the task you have to complete. Just find out how much time spent, then use
The order can be skilled. This will then focus on your documentation.
The following sections give the operations encountered by most people. You use them in actual work.
Three basic steps.
Don't knock twice
The collections we use are limited. It is not only a limited number of phrases and sentences. for
This is even more such. Obviously, you don't want to knock the same thing twice.
You often want to replace a word into another. If it is a full file replace, you can use
: s (substitution) command. If only a few locations need to be replaced, a quick way is to make
Use the * command to find the next word, use CW to replace it. Then knock
n Find the next word, use. Repeat the CW command.
The command repeats the last change. The change here is insert, deleted, or replaced. Be able to repeat
The operation is an extremely powerful mechanism. If you use it, then most of your editorial work may
It's just a few down. Be careful not to make other modifications twice, because this
Will change the operation you want to repeat. If you do need this, you can use m to remember to repair
The changed position, the other repeat operations will turn over and modify it.
Some function names and variable names may be difficult to knock. You can import accurately
`` XpmcreatepixmapfromData ''? Vim automatic complement mechanism can save you a lot of things. It looks at
You are editing the files and #include files, you can only type `` xpmcr '', then use
The ctrl-n command allows VIM to fill it into `` xpmcreatepixmapfromData ''. This is not only saved
The input time and the input error is reduced.
If you have the same phrase or sentence to enter multiple times, there is a simpler way. Vim can be carried out
Recording macro. Use the QA command to record macros in the 'A' register. Then enter the normally
The command command, finally use Q to exit the recording status. If you want to repeat the recorded commands, just need
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,
May wish to try it.
It should be noted that the recorded command will be repeatedly executed. Simple repetition macro when positioning
Operation may not be the result you want. For example, for a word here, you may need to move down 4 characters, under
It may be left to move 5 characters left. 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 time you can write a foot
This or macro. This is often used to establish a code template; for example, a function head. You want to do more smart
Make more smart.
If you know the error
Error will often be mistaken when editing. 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. Can be used
Write (abbreviation) for amendment. Here are some examples: *: Abbr Lunix Linux
*: Abbriss Across
*: Abbr HTE THE
These words are automatically corrected when editing.
The same mechanism can also be used to abbreviate long words. Especially suitable for inputs those you feel hard
Knocking words, it can avoid mistakes. such as:
*: 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 abbreviations.
Words do not appear in the article.
Vim provides a very smart highlighted mechanism, which is generally used for the grammar of the program, but can also be used
Follow the wrong.
Syntax highlights use color display comments. This is not a particularly important function, but once
It will be useful to find it very useful. You can quickly find that those who don't have highlighted but should be commented.
Text (probably because I forgot to knock the hinder). You can also find some code that is missed as a comment (
It can be because I forgot to knock the `` * / ''). These errors are difficult in black and white mode, and there are a lot of waste.
Debugging time.
The syntax is highlighted can also be used to find mounting parentheses. An unsatched ``) '' will be bright red background
Identify. You can use% commands how you match, then put the `` ('' or
``) '' Inserted into the right position.
Another type of mistake is also very easy to find, such as the `` #include
`` #included
It can quickly discove it `` include '' can be highlighted and `` incruded '' is not.
Look at a more complex example: For English text, you can define a long list of words to use.
All words that are not appearing in the table may be wrong and highlighting. Can define a few for editing
Macro of the word table. This is the spelling feature of the word processor. Vim is implemented by some scripts, you
It can also be customized: For example, only the text in the comment is spell check.
Part II: Edit multiple files
The document is always helping
People rarely edit only one file. Generally require sequential or editing some related files. You should benefit
Use the editor to make multi-file editing more efficiently.
The logo (tag) mechanism mentioned above also supports cross-file search. The general practice is all the files for the project.
Being a logo file, then search for functions, structures, types (TypeDef), etc. in all files of the project.
Righteousness. This is more fast than manual search; I browsed a program to do, the first thing I have to do is to establish a logo
Part.
Another powerful feature is to use: GREP commands to search for a set of files. Vim
Search results are a list and then jump to the first result. Use: CN command jumps to
A result. If you want to change a function called, the number of parameters is useful.
There are many useful information in the header file. However, you need to know which header files appear in a statement.
A lot of time. VIM can understand the header file and can find what you need. Move the cursor to a letter
Under numbers, then knock [i: Vim "all matching of the function name in a header file.
If you want to get more detailed results, you can jump directly to the declaration. A similar order can be used to detect
Check that the header file you use is correct.
You can separate the editing area of the VIM to edit different files. You can be two or more
The file is compared, or copy / paste. There are a lot of commands to open the closing window, the file is jumped, temporarily hidden files, and more. You can use the three basic procedures mentioned above to select the appropriate command.
Learn.
There are more usages in multiple windows. Preview-tag is a good example. It opened one
A special preview window, the cursor remains in the file you are editing. The preview window can be a cursor
The declaration of the function of the function. If you move the cursor to another name, stay in a two second, the preview window
The definition of that name will be displayed. The name can also be the structure or function declared in the header file.
Let us work together
Editor can edit files. The e-mail program can send and receive messages. The operating system can run the program. Each
The programs have its own tasks and should be done. If you can work together, you will implement it.
Very powerful feature.
To make 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 function is
Add to the compiler. But look at `` man sort '', know it has a lot of options. It may be used
An extremely delicate sort algorithm. Do you still plan to add it to your editor? What's more, there are many other things.
Filter. The editor may become large.
An embarrassment of UNIX spirit is to provide independent procedures, each doing your own tasks, then combine
Complete bigger tasks. Unfortunately, many editors do not work well with other programs, for example,
You can't package the Netscape's mail editor to replace it with another editor. This way you can only use that.
program. Another trend is to provide all the features in the editor, Emacs is a representative (someone said
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. Current Vim is already available
Editor of MS-Developer Studio and Sniff. Some E-mail programs (such as MUTT) also support
Department editor. And Sun Workshop integration is in progress. In general, this area is still waiting
high. In the future, we will have a system greater than its partial part.
Text structure
You may often encounter texts that have some structures, which may be supported by those existing orders.
structure. So you have to use those underlying `` bricks '' to create your own macro and script. Here
This is the more complicated thing.
There is a simple way to speed up editing - compile - modify this loop. Vim provides: make life
Order, used to compile, and get an error output, and correct it to an error. Such as
If you use another compiler, then the error cannot be obtained by Vim. If you don't want yourself, you can
To modify the 'ErrorMAT' option. Tell the VIM error what is like, and how to get
Get 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 in Man
The manual is jumped, you can write a macro to get the word under the cursor, clear the buffer, then read 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 you want to say
The operation taken, then find the corresponding command to use it. It's so simple, you just want to do it.
.
Part III: Worm
to form a habit
I have to learn to drive. Is this why you only ride a bicycle? Of course, you will find
You have to spend 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. Big
Most people only need to learn 10% to 20% of orders. But everyone needs for each person
Various. You need to continue to learn and find out that you can complete it. If you only do one
Operation, and will not do it later, then it is not necessary to optimize. Yes if you find you
After another hour, repeat the same operations several times, then it is necessary to check out the manual, see if
Complete faster. Or write a macro to do it. If it is a small task, for example, for a class of text
On the line, you need to read the newsgroup or see if someone has solved the same.
problem.
The most fundamental step is the last one. You may be able to find a repetitive task, find one
The wrong way can I have forgotten what I have done in a weekend. This is not. You have to repeat
Your practice until you are cooked. Only at this time you really get the efficient you need. Don't learn at a time
too much. I only try to work very well at a time. For those uncommon techniques, you may only need
Remember it and leave it later. In short, if you hold such a goal, your editing skill will be more
Effective.
Finally, it is necessary to point out, if people ignore what will happen: I can still see someone
Staring at the screen for a long time, knocking a few points in two points, then continue to look up and look at the screen, and complain that you are too
Tired .. Use ten points! This is not too fast, not tired. Take an hour to practice every day.
Act, as long as it is enough for a few weeks.
postscript
The title of the book benefits from Stephen R. Covey, the best-selling book "Seven habits of high-efficiency people" (`THE 7
Habits of highly effective people '').
About author
Bram Moolenar is the main author of Vim. He wrote Vim core function and adopted many developers.
The code provided. His e-mail address is: bram@moolenaar.net