Editor tool for ordinary people-VIM

Source: Internet
Author: User
Tags ultraedit

Turn from good use soft: http://blog.sina.com.cn/s/blog_46dac66f010005kw.html

Writing Time: 2006/12/04

In last May, I started using vim. Since then, I 've gotten better off, and I'm sorry that I gave up pirated ultraedit due to copyright self-discipline. In addition, I learned from Vim what is the real tool for editing. When I make good use of Jia soft or other forum posts, I first input in Vim, and easily and efficiently edit the format, and then paste it online. My address book, notes, Reading Notes, and work records are also completed in vim. Including some documents and data processing. It will also improve the efficiency of vim. In a word, since I used vim, I have been infatuated with it, and it almost exceeded total commander. However, I strongly recommend that you use irfanview/xnview to replace ACDSee, use 7-zip to replace WinRAR/WinZip, and use gimp to replace Photoshop ", but Vim is not recommended to replace ultraedit. This does not mean that Vim is not competent. On the contrary, if there is still a gap between alternatives such as irfanview and the original shared software, VIM is far better than ultraedit. The only reason not recommended is that Vim is a little difficult for beginners.

But today I wrote this article to recommend it to you. There are two reasons: first, the editors have chosen a question and want to preach vim and Emacs to the public. This courage inspired me. Second, I have published an article by two masters (Emacs is a kind of belief in Wang yinzhi! Introduction to the world's strongest Editor, dieken's editor for programmers-Vim) may scare people who are interested in them and I will make some corrections.

Therefore, this article includes two parts: one is to help beginners experience vim. This part is like an experiment tutorial. It uses multiple examples and the style of text is as silly as possible, so that new users (including vim, which has never been heard of before) can experience Vim step by step according to my operations. The second is to introduce my application, that is, how Vim facilitates my daily work and life, rather than programming.

1. Basic Introduction to VIM

Vim is a super powerful text editor. It is an order of magnitude with Emacs, and I think it is one (at least half an order of magnitude) higher than ultraedit, editpad, and emeditor ). If you are interested, read the editor of the programmer-Vim to give you a more detailed and comprehensive theoretical understanding of vim.

Key Aspect 1: vim and its predecessor VI have a long history (may be older than most readers). It has been tested and developed for decades and is trustworthy.

Key 2: Vim has a mode. In general, let's make a comparison. Notepad has no mode (or only one editing mode). Press J to enter J in the body. To save the mode, press Ctrl + S. To move one row down, the cursor or mouse is required. In vim, after opening a file, it is not in the editing mode, but in the normal mode. At this time, you press J. Vim does not think that you need to input J in the body, instead, the cursor moves down a row. Press I to enter the insert mode, that is, the edit mode, that is, the notepad mode. In edit mode, Press ESC to return to normal mode. In normal mode, press: To enter the command line mode, which is used to enter more complex commands. For example, W indicates saving the file, and E a.txt indicates opening the file a.txt. That is, VIM can be used without the mouse, direction keys, menus, Ctrl, alt ...... Issue a command. Therefore, remember to enter the correct mode in the following experience: ESC to normal; normal I to edit; normal: to the command line. Another note is: In this article, the command line mode is used for headers, and most normal modes are used for headers.

Key Aspect 3: complex confrontation. Some of Vim's command lines are very scary, with a long string of characters like tianshu. These seem complicated, but they are actually just a combination of some simple commands. With this, VIM users can achieve very complex requirements. If you do not have such requirements, you do not need to care about them.

Key Aspect 4: A hundred energy. This is a significant advantage of Unix or command line software and can be deeply understood through practical use. Although there are some examples in this article, it is still not fully presented with a sense of success and perseverance. For example, if a software in Windows claims to be able to cook, it means you can click the menu and make the dishes ready-this is an easy-to-use philosophy. In the end, you do not have much say, but are solidified by software developers. If Vim can, there is a "Cooking" command, you can combine this command with the original "raw material", "quantity", "fire", "flavor", and "cooker" command, even Add "buy food" and "wash food" in front of it, and then add "Attach disk" and "wash dishes" to form an automatic script, which is automatically executed when appropriate.

Key Aspect 5: unlimited flexibility. Vim can almost meet your specific needs. Therefore, VIM is different for different people, that is, the downloaded Vim is configured as its own vim.

Stop now and start your experience!

2. Download and install

Vim is cross-platform. In Windows, we use gvim for Windows. The latest version is 7.0. The downloaded package is about 8 MB, and about 20 mb after full installation.

Note: The volume is too large? If you are a master, you can delete unnecessary files (including help files, which are the best help of the software I have ever seen). The size of the simplified file can be less than 2 MB. Or, download a gvim.exe (1.5 MB) to run it. However, for this experience, we recommend that you install all the items by default to achieve the expected results.

Download pconline, official download

Install it. Basically, you just need to install agree and next. I usually install it in D:/program files/vim.


3 experience

3.1 initial interface

After the installation is complete, follow the prompts to open readme. You will see

Or you can directly run D:/program files/Vim/vim70/gvim.exe by opening the shortcut on the desktop. You should see the interface as follows:

What? Ugly? Earth? This is also the first time I saw it, but now I only feel cordial.

Is it a Chinese interface? Do I download the Chinese version for you? Will the rogue plug-in be bundled? If you think so, I can only sigh.

3.2 trial html

Save the web page as htm, such as test.htm, and use Vim to open it. Use the menu temporarily! The result may be as follows:

It's no surprise, right? Because it is a standard vim, and the performance is preferred, the effect is ignored by VIM. Anyway, please enter the command line mode (that is, click the colon, note that it is an English colon :), and notice the changes in the bottom line. Enter sy on and then press Enter. Is there a color? It should look like this

Important: For simplicity, we will use

: Sy on

(Confirm in Normal mode first. If you do not confirm, Press Esc several times.) Press: To Enter command line mode, enter sy on, and then press Enter.

Note: sy indicates that the syntax is highlighted and on is enabled. : Sy clear indicates that the highlight is canceled.

3.3 face change

To experience VIM, we need to follow the VIM idea, so we need to change gVIM back to the original face of VIM.

By the way, if you think its interface is very earthy, please take a closer look at the current look, because the following operations may be more earthy!

Run the following command:

: Set go =

In this case, VIM should be

Don't make a fuss, isn't the menu and toolbar gone? They should not be used in VIM.

Note: set indicates general settings. go is the abbreviation of gui option, that is, the interface.

Enter a half-life order (do not press enter first)

: Colo ev

Click the tab key. Is it true that auto-completion is evening? VIM is very intelligent (but not as clever as MS Word ).

Then you press Enter. What do you see?

Is it dark? That's right. Now it's evening.

Note: colo is used to set the color scheme. VIM comes with nearly 10 color schemes. Of course, you can download more or adapt your own color schemes online. You can directly click the "colo" tab and select different color schemes to try it out. Of course, evening is a classic one. I always use it.

3.4 prepare and open the sample file

For more information, download test.txt and save it as d:/test.txt. Then, enter a half-life order in VIM.

: Tabnew d:/t

If you do not need to go back to the terminal, the vimwill automatically replace the value with test.txt after you press export tab. If not, press the tab several times until it is correct. Then press Enter.

You will see that vimhas opened test.txt and is using a multi-page tab. You can click the tabs to switch between the opened files (Master has more convenient Keyboard Command practices ). This function is not available in VIM6.3. Of course, this does not mean that VIM users cannot enjoy the convenience of Multi-page signatures. After downloading a plug-in, VIM has thousands of plug-ins. In the face of the popularity of the Multi-page signature style (IE6 → Maxthon → IE7), VIM7.0 also adds this feature.

I like this simple tab. If you think this tab is too ugly, try: set go = e

The following results apply:

3.5 unified format: Download vimrc

The above commands are all about VIM settings. Writing them to a _ vimrc file becomes the default option. Each VIM user's _ vimrc file is different because each user's needs are different.

To ensure the following operations have expected results, download my _ vimrc. Perform the following operations in sequence:
① Close all VIM

② Copy your d:/program files/vim/vim7/_ vimrc file.

② Right-click here and "Save as" Overwrite your d:/program files/vim/vim7/_ vimrc.

Note: This is not a standard practice, but it is more convenient for windows users.

3.6 open test.txt

Run the following command again: Esc to Normal; Normal to edit; Normal to command line.

Run VIM and execute

: E d:/test.txt

Next, we will arrange this article. If you think the file can be edited manually, copy the file to row 3 and post your comments.

3.7 segment and save

There is no segmentation in the original text. Observe and find that the following is ......" Press enter.
: % S/The following are // r &/gc

After the input, the interface is as follows:

And prompt, please answer y or. If you reply to Y, replace the current one. To the next one, VIM will ask you again. Therefore, after answering a few y s, you may as well replace them all with.

Note: "S" indicates replacement; "s/a/B/" indicates replacement of "A" to "B"; "/R &" indicates replacement of "below", and "/R" indicates carriage return, & indicates the part to be replaced, that is, "Below is"; % indicates the full text;/GC indicates that it is always replaced (not just replaced by the first one), and requires user confirmation.

Take a look at the file. It may be better to leave two lines blank. Just repeat the command. However, for the powerful vim, you do not have to enter the previous command in a clumsy manner. In the command line, press:, and then click rotate (the upward direction key). Can you see the command just now? Press enter directly. Enter a when asking a question. The task is completed.

Save the changes as soon as possible. Command is

: W

Of course, you can also press Ctrl + S. However, CTRL + S is effective because I defined it in _ vimrc: When Ctrl + S is pressed, the system executes the W action. Therefore, you can define other hotkeys and map them to W.

3.8 continue editing

First, delete the word "stick", which is very simple. Just press gg2x. To see the effect, you can separately Press:
GG, then move the cursor to the header of the article.

2 characters are deleted.

Try the magic of VIM again, for example, press 5x, so the five characters disappear. Of course, these five characters must be retained. It doesn't matter. If you press u once, will you return?

Press Ctrl + R again, isn't it? Again U, isn't it back? Yes. U and CTRL + R are equivalent to (not equivalent to) Windows undo and redo.

TRY dd again. Is the entire row missing? It doesn't matter. You can just return U.

Try 3DD again. Three rows are deleted at once! It doesn't matter. U is back.

Another DG. Wow, the full text is gone ?! Still u back.

3.9 edit more

TaskA: Divide each sentence into one line to achieve the following results:


Shame on,

Solution: If you remember the replacement command above, you will think that you can replace it with two times ("proud", "for" proud "," and "Press ENTER", "Shame", and "Shame, "And press Enter ). However, these two replications can be completed at one time in Vim, that is, using a regular expression, in the "as" and followed by 2 characters ("rong," or "shame ,") and then press Enter. How to express it?

: % S/is ../&/R/GC

Check the highlight. No problem. Directly.

Wow, is it spectacular? Don't you think? What if there are one thousand rows and 10 thousand rows?

TaskB: Remove the punctuation marks at the end of the line, that is"Rong"And"Shame".

Solution: there are too many solutions, and you can still replace them. A new feature, column operations, is shown here.

For safety, press esc twice and then Gg $. Then, the cursor is directed to the last character in the first line of the article, that is, the comma.

Press Ctrl + V to check whether the "visible block" is displayed in the status bar. (Make sure you have used the xbeta _ vimrc file. If not, Try Ctrl + Q)

15jx, are all punctuation marks deleted? Because 15j indicates 15 rows are selected downward, and X indicates deletion.

TaskC: Incorrect

Operation: this operation demonstrates the usage of macros. Follow the instructions in this tutorial.

Make sure that the input method is not enabled, and ESC is in normal state, GG is in the beginning of the article.

Start recording macros by QA (Q, macro name is)

Shift +> (hold down shift, press twice>, and then release shift. At this time, the first line should be tab backward)

Then J ^ (move down a row and place the cursor at the beginning of the row)

Shift +> SHIFT +> (that is, two tabs in the second row)

J ^ (move down a row and place the cursor at the beginning of the row to prepare for subsequent operations)

Q again (this indicates that the macro recording is complete, and VIM will prompt that the recording is complete)

In this way, the macro recording is complete and can be used.

@ A again. Have you seen the effect? The macro is executed once, that is, 3 and 4 rows are successfully executed. There are still 6 sections left, but you don't need to press @ a 6 times, but you just need to press 6 @ !!!

Amazing! Play back? First u, then 6 @. Since it can be 6, of course it can be thousands of thousands!

Note: The use of VIM by experts is ever-changing. The first two operations (branch + Delete punctuation) above can be combined into one: % s // (. /). // 1/r/gc; or merge the 3rd operations (which are incorrect) into the previous operation.

3.10 free trial

Experience moving the cursor: Please press j and k at will to see the reaction; then press l and h to see the reaction; then, when your cursor is in English, press the number w and B.

By the way, every function of gVIM is infinitely possible. Therefore, you can add a number before a few letters, such as 9 w 2 h, to check its response.

Experience auto-completion: I come in, so far I haven't written any words! For the sake of simplicity, place your mouse on the next line in Chinese. Let's enter Eight Do's and Eight Don's. However, enter an E. Do not move it first! Press ctrl + p to automatically complete?

Try cases (u is used to restore the original state after each operation ~~ And guu and gUU and g ?? (G ?? Then you can press g ?? Can also be restored)

Amazing? This is a single performance of VIM functions. The real expert is to combine them to meet your own unique editing needs.

3.11 experience syntax highlighting and folding

This part is too complicated. If you have other editors such as UltraEdit basics, it will help you understand. However, UltraEdit is memorable because VIM is powerful and flexible in this regard.

Still the original file we edited. for simplified calculation, download test2.txt; download tx1.vim and save it in d:/program files/vim/vimfiles/syntax/tx1.vim

Open it with VIM (for example, to open d:/test2.txt, use tabnew d:/test2.txt in VIM. It's just plain, right? This is because VIM does not know that this file should be highlighted. Enter a command: setf tx1, which is equivalent to telling VIM that the file type is tx1. Therefore, highlight and collapse the file according to the downloaded tx1.vim file.

Then you will find that test2.txt is fully broken down. How to open it? You can click + on the far left. Of course, you can also use the command zr or zR to open (zR to open all; zr to open the current; zM to fold all; zm to fold the current ). After opening, you can see the highlighted effect. You can set the foreground color, background color, bold, oblique, and underline style for the text.

3.12 encrypted file

Text files are the fastest to open, easy to edit, and easy to search in VIM. Therefore, I use it to keep a diary and use it as the address book. But what about security issues? It's easy. VIM itself can be encrypted (VIM is also used for recording and decryption ). In the above-opened file, Type X (uppercase X), and VIM prompts you to set the password. For security reasons, check the password for 2nd times. Then, save (type: w ). Shut down VIM or this file, and enter the password when opening it again. Only by entering the correct password can you get the correct file.

4. My applications

Like VIM and Total Commander, I set them to automatically run at startup, and their applications are countless.

For example, if I do not use any software, I use vimto manage a address.txt. It can be implemented: Quick Start (I defined bookmarks in VIM and typed 'a to open it), encryption (using VIM's: X), and super-powerful search (needless to say ), hide group (fold), highlight email and phone number (custom syntax file.

For another example, I will use VIM to assist with word, excel, bbs, safe file deletion, and the creation of a simplified five-word dictionary. For more information, see my commonly used VIM functions, live learning and making good use of gVIM to improve work efficiency: examples (collections), and articles such as creating a personalized notebook with gVIM.

The following two figures show my personalized txt example and how I wrote this article using VIM:

5 postscript

This article is much longer than originally planned, but I still feel that many excellent features are not mentioned. For example, now I write this article, and of course I use VIM. However, the htm format is used because of illustrations. When inserting an image, I only need to input img, VIM will automatically replace it with "& lt; img src =" "& gt;", and place the cursor in the middle of two quotation marks, so that I can enter the image name. After I enter lnk, VIM will replace it with "& lt; a href =" "& gt; & lt;/a & gt ;". When I want to see the effect, I only need :! G:/study/it/pconline/vim/xbeta-vim.htm it automatically opens in the browser. This long path is also very easy because of its automatic completion and command line history. But when some URLs are not yet determined and need to be labeled, I will use a '1', and VIM will be marked with a striking red block for a clear view. The next time you open this file, it will remember the last location I edited.

Before using VIM, I tried dozens of pad and editor types, including long-term Editpad, UltraEdit, EmEditor, and EditPlus. But with VIM, I no longer care about thousands of editors in the windows world. Because the logic for using them is "If there is a new requirement, you can only wait for software upgrade or another software", while the logic for using VIM is "If there is a new requirement, please make personalized configuration or download the plug-in ".

VIM is in the hand. How can I help you!

Finally, I would like to pay tribute to VIM's spirit of excellence and open-source sharing! We hope that users with a sense of responsibility will gradually reduce piracy!

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.