About VIM for Windows

Source: Internet
Author: User
Tags add numbers save file ultraedit

Editor's tool for ordinary people--vim (for Windows)

This article is reproduced from the Vincent_czz
In May 2005, I started using VIM. After getting better and better, originally because of copyright self-discipline and abandon the ultraedit of the regret swept away. And, from vim, I realized what a real editing tool is. In the use of good soft or other forum posts, I was first in the vim input, and convenient and efficient editing of good format, and then posted to the Internet. And my address book, my notes, my books, my work.

The record is also done in Vim. Including some documents, data processing, let vim over a bit, will also improve a lot of efficiency. In a word, for self-use VIM, it has a fascination with the day and is almost over total Commander. However, as the best use of the good soft and forum posts, I strongly recommend "replace ACDSee with Irfanview/xnview, 7-zip instead of winrar/winzip, use GIMP instead of Photoshop", but did not recommend vim instead of UltraEdit. This does not mean that Vim is not competent, on the contrary, if IrfanView and other alternatives than the original shareware there are some gaps, vim is far better than UltraEdit. The only reason for not recommending it is that vim is a bit difficult for beginners.

But today still wrote this article recommend to everyone. Two reasons: One, the editor of the adult selected the topic, to the public to preach vim and Emacs, this courage inspired me. Second, has issued two masters of the article (Wang Yin's "emacs" is a kind of faith! The world's strongest editor introduction, Dieken's "Programmer's editor--vim"

May scare some of those who are interested in them, and I'm going to make some corrections.

So this article has two: first, to help the novice experience vim. This part is like experimental tutorials, multi-use instances, and the style of writing as much as possible to fool, so that the novice (including never heard of Vim) can follow my operation, step by step experience vim. The second is to introduce my application, that is, how vim facilitates my daily work and life, not programming.

1 Basic Introduction to VIM

In a word, VIM is a super super powerful text editor. It is an order of magnitude with Emacs, and I think it is one (at least half order) higher than UltraEdit, EditPad, and EmEditor. If you are interested, you may wish to read the programmer's editor--vim, so as to have a more detailed and comprehensive theoretical understanding of VIM.

Important 1:vim and predecessor VI, a long history (probably older than most readers), has experienced decades of testing and development, trustworthy.

Important 2:vim has a pattern. Make comparisons in layman's way. Notepad no mode (or only one edit mode), you press J, that is, enter J in the text, to save, you need to CTRL + S; To move one line down, ↓ or mouse. In Vim, after opening a file, not in edit mode, but in normal mode, when you press J,vim do not think you want to enter J in the body, but instead of moving the cursor down one line. Press I to enter insert mode, that is, edit mode, which is the Notepad mode. Edit mode Press ESC to return to normal mode. In normal mode, press: Enter command-line mode to enter more complex commands. For example: W for Save file,: E a.txt for open file a.txt. That is, VIM can be used without the mouse, arrow 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. One more point is: In the text: The beginning is the command line mode, in addition to most normal mode.

Point 3: Complex confrontation complex. Vim has a very scary command line, a long string of characters as the Heavenly Book. These seemingly complex, in fact, are simply a combination of some simple commands. With this, VIM users can achieve very complex requirements. If you don't have that kind of demand, you don't have to ignore them.

Point 4: One can be hundred. This is a significant advantage of UNIX or command-line style software, which can be deeply realized through practicality. Although there are some examples in this paper, it has not been fully demonstrated by its great use and the sense of its own heart. Here, for example, if a software under Windows is known to stir-fry, it means that you click on the menu and the dish is ready-this is the philosophy of ease of use. You don't have much say in what you do, but it's cured by software developers. And if Vim says yes, then it has a "stir fry" command, you can put this command with the original "raw" "Quantity" "Heat" "Flavor" "cooking" command combined with, even before it with "buy vegetables" "wash vegetables", followed by "plate" "Wash dishes" made an automatic script, executed automatically in the appropriate case.

Point 5: Infinite flexibility, individuality by me. As long as you have specific needs, VIM can almost be satisfied. So different people's vim is not the same, that is, the download of vim configured to their own vim.

Stop here and start the journey of experience!

2 Download and install
Vim is a cross-platform. Under Windows, we are using Gvim for Windows edition. The latest is version 7.0, download package about 8MB, completely installed after about 20MB.
Note: Volume is too large? If you are a master, you can completely delete the unused files (including Help files, it is the best software I have seen the Help), the volume can be reduced to less than 2MB. Or vice versa, download only one gVIM.exe (1.5MB) to run. For this experience, however, it is recommended that you install all of the default items for the first time so that you can achieve the desired results in this article.
Pconline Download, official download
Installation, basically, has been agree, next on the line. I usually put it under the D:\Program Files\vim.
Refer to








3 Journey of experience
3.1 Initial interface
After the installation is complete, follow the prompts to open the Readme and you will see

or open a shortcut to the desktop yourself, or run D:\Program Files\vim\vim70\gvim.exe directly, you should see this interface:

What the? Ugly? Soil? The first time I saw it was the same feeling, but now I feel only cordial.

A little more, do you wonder if it's a Chinese interface? Did I download the Chinese version for you? Will not bundle rogue plugins ah? If you really think so, I can only sigh without words.

3.2 Probation html
Please save this page as an HTM, such as test.htm, and then use VIM to open it. Use the menu for the time being! The result may be this:

It's mediocre, isn't it? Because it is a standard vim, and is a performance-first, visual effect ignores vim. Anyway, go to command-line mode (just click the colon, note the colon:), and notice the change in the bottom line. Then enter SY on and then enter. Does it have color? It should look like this.

Important reminder: For simplicity, the following
: Sy on
Indicate (confirm in normal mode, if not confirmed, press ESC a few times) you first press: Enter command line mode, then enter SY on, and then enter.

Supplementary Note: Sy means the syntax is highlighted, on of course it is open. : Sy clear indicates de-highlighting.

3.3 Makeover
The experience of VIM will follow vim, so we have to change the Gvim back to the original vim.
By the way, if you think its interface is very earthy, please look at the current look more, because the following operation may be more Earth!
Execute the following command
: Set go=
The VIM at this time should be

Don't make a fuss, is the menu and toolbar missing? They are not supposed to be used in vim.
Add: Set represents a general setting; Go is the abbreviation of GUI option, which is the interface; equal to NULL is nothing.
Then enter half of the command (do not return to the first)
: Colo EV
Then, press the TAB key. is the auto-completion for evening? Vim is very clever (but not as smart as MS Word).
And then you return to the car and see what?

Is it all dark? Yes, it's evening now.

Supplementary NOTE: Colo is the setting of the color scheme. Vim comes with nearly 10 different color schemes, and of course you can download more on the Web or adapt your own color scheme. You can try it directly in: Colo (plus a space) on the tab, choose a different color scheme to experience. Of course, evening is a more classical one. I've been using it.

3.4 Preparing and opening the sample file
For simplicity, download test.txt and save as D:\test.txt. Then, enter half of the command in VIM
: Tabnew d:\t
Do not enter after the loss, click Tab,vim will automatically fill the test.txt. If not, press TAB several times until it is correct. then enter.

You'll see that Vim opens the test.txt, and it's a multi-page (tab page) way. You can click on each tab to switch between the open files (the master has more convenient keyboard command procedure). In VIM6.3, this feature is not yet in. Of course, this does not mean that users of vim can not enjoy the convenience of multi-page signing, download a plugin after--vim have thousands of plugins-on it. VIM7.0 has also added this feature to the popularity of multi-tab styles (IE6→MAXTHON→IE7).
I like this simple page sign. If you think this page is too ugly, try it: set go=e
This should look like the following effect

3.5 Unified format, download VIMRC
The various commands above are the settings for vim. Writing them into a _VIMRC file is the default option. Each vim user's _VIMRC file is different, because everyone's needs vary.
To ensure that the following actions are expected, please download my _VIMRC. Perform the following operations in turn:
① Close all Vim
② Find your D:\Program FILES\VIM\VIM7\_VIMRC, copy one.
② Right click here, "Save as" to overwrite your D:\Program FILES\VIM\VIM7\_VIMRC.

Note: This is not a standard practice, but it is a convenient option for Windows users.

3.6 Opening Test.txt
Remind the mode again: ESC to Normal;normal under I to edit; normal: to the command line.
Run vim and execute at the command line
: E d:\test.txt
Next, let's put this article in the line. If you think you can make a manual layout, please copy this file to 10000 lines and then comment.

3.7 Segment and save
The original text is not segmented, observe, found can be in the "following is ..." Front plus enter, so
:%s/the following is/\R&/GC
After input, the interface is as follows

and prompt, please answer Y or a. If you answer y, replace the current one, and Vim will ask you again at the next. So, after you answer a few y, you might as well replace it with a.
Supplemental Note: s means substitution; s/a/b says change A to B; the previous command is to change the "following" to "\r&", and \ R to indicate that the carriage return,& represents the part that is replaced, that is, "the following is";
Looking at the file, you might think that empty 2 rows might be better. It's very simple, just repeat the order just now. However, for a powerful vim, you don't have to be stupid to repeatedly enter the last command. At the command line, press: And then click ↑ (UP ARROW key), see the order? Go directly to enter, ask for a, task completed.
Change, please keep it in time. command is
: W
Of course, you can also press Ctrl+s. But Ctrl+s is effective because I made a definition in _VIMRC: When I press ctrl+s, the system executes: w action. Therefore, you can define the other hotkeys completely and map it to: W.

3.8 Continue editing
First delete the word "stick", very simple, just press gg2x on the line. To see the effect, you can press separately:
GG, at which point the cursor moves to the article header.
2x, 2 characters were deleted.
Once again experience the magic of vim, such as pressing 5x, so 5 characters disappear. Of course, these 5 characters are to keep, it's okay, you press once u, come back?
Press the Ctrl+r again, is it not again? One more time u, is it back again? That's right. The U and ctrl+r equivalent (is equivalent to not the equivalent) of Windows Undo and redo.

Try DD again. Is the whole line gone? Never mind, u come back on the line.
Try 3dd again. Deleted 3 rows at a sudden! Never mind, u come back.
Another DG, wow, the full text is gone?! Still u back AH.

3.9 More Editors
Task A: Each sentence is divided into one line, that is to achieve the following effect
Proud of the * *,
Shame on the * *,
Solution: If you remember the above replacement command, you will think that can be replaced with 2 times ("For Glory," "for the Glory," plus carriage, "ashamed," for "Shame," plus carriage return). However, these two substitutions can be completed once in Vim, with a regular expression, followed by a carriage return after "for" and 2 characters ("Rong," or "Shame,"). What do you mean?
:%s/for. /&\r/gc
Look at the highlights, no problem, direct a

Wow, isn't it spectacular? Don't you think? What if it's 1000 rows and 10,000 rows?

Task B: Remove the punctuation at the end of the line, that is, the comma after "Rong" and the comma after "shame".
Solution: Too many ways, can still be replaced. But here's a new feature: column operations.
To be safe, press ESC twice, then gg$ the cursor to the last character in the first line of the article, which is comma.
Press CTRL + V to see if the status bar is prompted with the word "visual block". (Please confirm that you are using the Xbeta _VIMRC file, if not, please try Ctrl+q)
15JX again, are all punctuation removed? Because 15j means to select 15 rows down, x means delete.

Task C: Patchwork
Action: This time to demonstrate the use of macros, please follow this tutorial strictly.
First make sure: Input method is not open, and ESC to normal state, GG to the first.
Press QA (q = Start recording macro, the macro name is a)
Shift+>> again (means hold down SHIFT, double-click &gt, and then release shift.) At this point the first line should be a backward tab)
j^ again (move down one line at a time, and place the cursor at the beginning)
Then shift+>> again shift+>> (i.e. the second row Backward tab two)
j^ (Move down one line and place the cursor at the beginning of the row to prepare for subsequent operations)
Again Q (indicates that the macro recording is finished, Vim will prompt the record to complete)
So the macro is finished, it can be used.
Again @a, see the effect of it? The macro was executed once, that is, 3, 4 rows succeeded. There are 6 paragraphs left, but you don't have to press 6 times to @a, but just press [email protected] !!!

It's amazing! Play it back, please? First U, one more time [email protected]. Since can be 6, of course tens of thousands!

Added: The master use of vim is ever-changing. The first 2 operations above (branch + cut punctuation) can be synthesized in one:%s/. /\1\R/GC, or merge the 3rd operation (patchwork) into the previous operation.

3.10 Free Experience
Experience Cursor movement: Feel free to press a few clicks of J and K to see the reaction, and then press a few more L and H to see the reaction; then, when your cursor is in English, press a few W and B.
By the way, every function of gvim is infinitely possible, so you can also add numbers to the top letters, such as 9w 2h, to see how it reacts.

Experience Auto-completion: I come in, so far have not written a word! For the sake of simplicity, you just put the mouse on the next line in Chinese, we put Eight do ' and Eight Don ' ts input again. However, enter an E, do not move! Did you press Ctrl+p to complete the auto-completion?

Experience case (after each operation, use U to restore the original), try g~~ and Guu and Guu and g?? (g?? After you can not press U, and then press G?? can also be restored to the original state)
Is it magical? This is also a single performance of the VIM function, the real master is to combine them together to complete your own unique editing needs.

3.11 Experience syntax highlighting and folding
This section is too complex to talk about. If you have other editors like UltraEdit Basics, it will help you understand. But Vim is powerful and flexible in this respect, and UltraEdit is memorable for its nape.
is still the original document that we edited, for the simplification of the meter, please download test2.txt; download Tx1.vim and save it in D:\Program Files\vim\vimfiles\syntax\tx1.vim
Open with VIM (for example, to open D:\test2.txt, in vim: Tabnew d:\test2.txt) it. Nothing strange, is it? This is because VIM does not know that the file is to be highlighted. Type a command: SETF tx1, which is equivalent to telling Vim that the type of this file is TX1, so highlight and collapse according to the tx1.vim you just downloaded.
At this point you will find test2.txt completely folded up. How to open it? You can use the mouse point to the left of the +, of course, may also be opened with the command ZR or ZR (ZR open all; The ZR opens the current; Zm folds all; ZM folds the current). When you open it, you see the highlight effect. You can set the foreground color, background color, bold, oblique, underline style for text.

3.12 Encrypting files

Text files are fastest to open, easiest to edit, and easy to find in vim. So I use it to keep a diary, and as my address book. But what about security issues? Very simply, vim itself can be encrypted (recorded and decrypted with Vim). In the above open file type: X (is uppercase X), Vim prompts you to set the password, for security purposes to confirm the 2nd time. Then, save (Type: w). When you turn vim or this file off, and then open it, you will enter the password. Only you enter the correct password to get the correct file.

4 My Apps
Vim and total Commander, I set them all to run automatically, their applications are countless.
For example, contact management, I do not use any software, using VIM to manage a address.txt. It can be implemented: Quick Start (I have defined bookmarks in vim, type ' A will open), encrypt (with vim: X), strong search (needless to say), group folding (fold), email and phone number highlighting (custom grammar file).
again, for example, the author will use Vim to assist Word, Excel, BBS posts, safe deletion of files, the production of streamlined Wubi thesaurus. See also the "I commonly used vim function", "live learn to use GVIM, improve work Efficiency: example (collection)", "use Gvim to create personalized notepad" and other articles.
The following two figures are my personalized txt example, and when I wrote this article with vim:


5 PostScript
This article is much longer than originally planned, but still feels a lot of very good features are not mentioned. For example, I am writing this article now, of course, with vim. But because of the illustrations, the HTM format is used. When I insert a picture, I just enter img,vim automatically as "</a> ". When I want to look at the effect, I just need:! G:\study\it\pconline\vim\xbeta-vim.htm It is automatically opened in the browser. And this long path is very easy because of the automatic completion and command line history. And when some URLs have not been determined, need to label, I use a ' 1,vim will be marked red block out, at a glance. The next time you open this file, it will remember where I last edited.
before using VIM, I have tried dozens of kinds of pad and editor, including long-term use of EditPad, has also been more proficient in ultraedit, has been measured EmEditor, editplus and so on. But after using VIM, I no longer care about the thousands of editors in Windows world. Because the logic for using them is "if there is a new requirement, you can only wait for software upgrades or a change of software," and the logic for using VIM is "personalize or download plugins if new requirements are available".
Vim in the hand, the husband how to beg!
Finally, we salute the spirit of excellence and open source sharing that VIM represents! and want to have the responsibility of users gradually reduce piracy!

About vim for Windows

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.