"Sometimes, people ask me if it is a sin in the church of Emacs to use the editor Vi. It is true that Vi-Vi-Vi is the editor of the beast...."

Just for once, I wouldn't mind siding with the beast if that is what it takes to use Vi. The modern avatar of Vi is Vim - the free editor created by Bram Moolenaar. Riding from strength to strength, this editor in its 7th version is a powerhouse as far as an editor is concerned. When ever I use Vim (or GVim for that matter), it gives me the impression of the Beauty and the Beast. It is very beautiful to look at - if you are like me who finds beauty in software , and it is also as powerful as a beast. I use this editor exclusively for all my editing needs that, when I use any other editor, I inadvertently press escape key. That should give you an idea of how ingrained the use of this editor has become in my computing life.

Vim 7.0 - the latest version has a slew of new features built into it. Some of them which I am aware of are as follows:

On the fly spell checking

Vim 7.0 has an on the fly spell checker built into it similar in lines to that found in Microsoft Word. By default, this feature is turned off. But by navigating to Tools -> Spelling -> "Spell check on", you can make Vim display all the mis-spelled words in your document. It does this by highlighting them with red coloured wriggly lines. And all it takes to correct the misspelled words is to move the caret to the highlighted word and while in "Vi Command mode", press 'z=' and Vim will show a list of words closest in relation to the misspelled words and the user can choose from them.

Fig: On the fly spell checking

Suppose, you want GVim to recognise the word GVim as a valid word. It is possible to tell the spell checker that GVim is a good word by moving the cursor on the GVim word and pressing 'zg' in command mode. On a similar vein, it is possible to tell Vim spell checker that a word is wrong by pressing 'zw'. Vim stores the good/bad words that the user recognises in a file associated with the variable spellfile. If the file is empty or not created, then Vim will create one automatically and store the words in this file for future use.

:]s - Move to the next mis-spelled word in the document.:[s - Same as above command but searches backwards.

z= - Shows a list of close matches to the mis-spelled word from which the user can pick the correct one.

Bracket highlighting

This feature is most useful for programmers than for ordinary users. Vim will automatically highlight the corresponding closing bracket when the caret is moved over any bracket. This helps in keeping track of the blocks of code and is especially useful when writing code which make use of multiple layers of brackets. Ofcourse this feature could take up some memory. But you can use the ':NoMatchParen' command to disable this feature.

Fig: Bracket highlighting

Omni completion

It is a smart kind of completion like the intellisense. It is most useful for people who write code. For example, if I am writing HTML code and I have saved the file with the extension .html, then Vim will automatically load the HTML tag file and when ever I want Vim to auto complete the HTML code, while in Insert mode, I press the key combination [Ctrl+x] [Ctrl+o] and Vim will smartly guess the correct keyword and insert it. If there is any ambiguity, then Vim will show the possible completions in a pop up window. This feature is presently available for 8 languages which include C, (X)HTML with CSS, JavaScript, PHP, Python, Ruby, SQL and XML. It is also possible to add custom omni completion scripts.

Fig: Omni completion - a boon to the programmer.

Open files in tabs

One of the most useful user interface is the tabs. Support for tabs in applications have been well received by the ordinary users that most web browsers and editors now support opening pages in tabs. Following this trend, Vim has also incorporated tab support in its latest version. And like all things related to Vim, it is entirely possible to open new files in tabs and manage tabs using the commands entered in the Vim Command mode.

Fig: Open files in tabs.

For example, while editing a file in Vim, I wish to open another file in a new tab. I can move to Command Mode and enter the command as follows:

:tabe /home/ravi/Desktop/myotherfile.txt

... and Vim will open the file "myotherfile.txt" in a new tab.

A few other tab manipulation commands are as follows:

:tabs - View a list of tabs that are open with the file names. Use the command ':tabs' and Vim will display a list of all the files in the tabs. The current window is shown by a ">" and a "+" is shown for any modifiable buffers.

:tabc - Close the current tab.

:tabnew - Open a new file for editing in a separate tab.

:tab split - Open the file in the current buffer in a new tab page.

:tabn - Switching to the next tab page.

:tabp - Switch to the previous tab page.

:tabr[ewind] - Go to the first tab page. You get the same effect when you use the :tabf[irst] command.

:tabo - Close all other tab pages.

Undo Branches

One of the things I really like about Vim is the use of the key 'u' to undo any changes. When ever I make a series of mistakes while editing a document, I just move to command mode in Vim and press the key 'u' a series of times to move to a point prior to the mistakes.

Fig: A list of undo levels with the time

In Vim 7.0, a new feature has been included which allows a user to jump back or forward to any point of editing. For example, I am editing a document and after a couple of minutes (say 10 min), I realise that I have made a mistake. I can easily take the document to a point 10 minutes back by using the command :

:earlier 10m

Or for that matter, move to a point 5 seconds ahead by using the command:

:later 5s

You can use the command :undolist to see a list of undo branches existing in the buffer. And each branch will have a number associated with it and it is possible to move to the undo level by using the command:

:undo <number>

Anybody who has used Photoshop will find that this feature is similar to the history levels you have in Photoshop, the only difference being that in Photoshop it is for images where as in Vim it is for text.

These are not the only new features. There are scores of others like Remote file explorer which allows one to directly edit a file residing in a remote location, better POSIX compatibility, Vim's own internal grep and so on which I have not covered here because this article is after all a visual walk through of the new features in Vim 7.0.

It takes real genius and stellar coding skills to create and maintain such a versatile editor and Bram Moolenaar has proved yet again that he has the necessary ingredients to qualify him for the post.

48
comments:

@anonymous It is paren highlighting and not paren matching as you put it. And it is indeed a new feature of Vim added in the latest version 7.0 as the author has stated in the article.

In earlier versions, it was possible to match the parens but it was not automatic; you had to move the cursor on top of a paren (bracket as the author puts it) and then press a key combination (I forget which) . And there was no highlighting of the brackets.

But now you can see the difference yourselves in the image above. The matching brackets are automatically highlighted.

In Vim 6, at least, you could set an option to make the cursor (but not the input point) jump to the opening brace/paren when you close the block. To actually jump back and forth you needed to hit %, which was also the way to check blocks that were already closed.

In earlier versions, it was possible to match the parens but it was not automatic; you had to move the cursor on top of a paren (bracket as the author puts it) and then press a key combination (I forget which) . And there was no highlighting of the brackets.

If only everything could be made in ITs mike Vim is : fast, multi-plateform, got many features but though remaine relatively simple to use, extensible and you can almost do everything you want with it, you are just limited by yuour imagination.

None of these features are things that I haven't seen in other editors. Even Windows editors are able to do most of this. Being able to check your spelling as you type is such an old feature that it shouldn't be vaunted in a review of an editor.

Putting Vim into a GUI and retaining the obscure key strokes is a little silly. And the key strokes are obscure. Why is "w" (wrong) the opposite of "g" (good)? Wouldn't "c" (correct) be a better antonym?

"Putting Vim into a GUI and retaining the obscure key strokes is a little silly. And the key strokes are obscure. Why is "w" (wrong) the opposite of "g" (good)? Wouldn't "c" (correct) be a better antonym?"

Ugh. I can't believe you would say that. Vi is so powerful the way it is. If they were to change the keystrokes they might as well call it MS Word and none of us would use it.

I like the new additions and I myself can't use MS Word without hitting Esc 40 times and I have j's all over the screen!

"None of these features are things that I haven't seen in other editors."

Right, because if its been done before it mean it can't be useful in any other application than the original implementation? Or is supposed to be some dig at VIM as an editor? If so, then so much more of the reverse would need be admitted. Pretty much every feature that exists in any text editor comes from either VIM or Emacs (and ed :). So should all of us VIMmers out there rag on Visual Studio for it hackneyed (not to mention poor) implementation of featues that VIM has had for MUCH longer?

"Putting Vim into a GUI and retaining the obscure key strokes is a little silly. And the key strokes are obscure."

No, the key strokes aren't silly or obscure. They may be esoteric, but definitely not silly. No, VIM isn't for everyone. Some people like things to be "simple". But don't confuse simple with easy. VIM is easy because of its key strokes (but because of them it may not be simple). But really, VIM, unlike most IDE's isn't designed to be editor you use for "right now". Its one of those tools most people who use it, will do so for ever - its the life-long editor. And as such, the keystrokes make you so much more productive than any IDE can. This isn't necesarily a debate point, just an observation. I guess it is one long-term investment that one can make to becoming a better programmer.

"The idea of VIM as a graphical based text editor is anathema."

Nope. Its just technology, not religion. Why so many people confuse the two is beyond me...

I have been using Vim since 6 years. Believe me in IT field editing in VIM is the only best thing i have ever encountered, other than programming. I am always ready for editing because of VIM and i will never get tired of it. Thanks Bram.

1 - Regarding the use of % to jump to a paired bracketing character -- that was brought along from vi.

2 - The previous disparaging review seemed a bit lame to me. Why should vim-GUI be "anathema"? And call me ignorant but I am unaware of text editors (as opposed to word processors) with most of these features. If you want to use MS Word, you get automatic spell checking, but none of the common Windows _text_editors_ can do it. And although it wasn't mentioned, vim can select and move rectangular blocks of text -- I know of maybe two other text editors (one of which was a old DOS "Word Processor" -- not very good as a word processor but not bad as a text editor) that can do it.

@ anonymous:First, GVim has existed for a long time. Second, retaining the keystrokes is not silly it is smart. Why should the behaviour be different? Many of us still maintain systems that have no X on them, but our local desktops do. Keeping the keystrokes the same means less learning and complexity.

Related to the features, again many of us use Vim on non-guified systems. When Windows editors are able to do theses things as well as run on non-guified systems you can have valid complaint. However, that is not the case.

Graphical Vim is a good idea. One that has been around for a long time. The ease of graphical dedicated windows, separation of console, and retaining existing knowledge and spead of keystroke sequences. Further, not all guified systems rely on mice there are many window manager systems that are designed to be operated entirely by keyboard. it is quite fast.

BTW, clearly you are not a Vi user. "c" is already taken, it stands for "change". Come back and grouse when you have just cause.

If you've ever used Vim, you'll know that there's nothing you can say to bash it. There's no text editor that is better.

I think you're getting text editors mixed up with word processors though. Word processors are text editors with a huge amount of bells and whistles. Vim isn't a word processor. It's a text editor that is mainly to speed up programming and such.

Graphical Vim has one advantage: when you switch the encoding (e.g. from cp437 to utf-8), it automatically refreshes the display, and you don't need to set the encoding of the terminal. On the other hand, when using the terminal, and the terminal supports UTF-8, you can set the termencoding option to "utf-8" to work around this. Besides this, too many terminal tabs are annoying, but an equal number of GUI windows aren't, so I prefer GVim when it's possible to use.

Actually, zc is used to close a code fold, so it's used already. Why the spelling and the code folding use the same first character, I dunno.

Also, the "new" tab feature feels more like an extension of the buffer switching feature that Vim has had for a while but with a much more visual metaphor that users are used to seeing in editors. In fact, I think that's what makes Vim so interesting -- people used to using a mouse in their editing tasks can comfortably use the editor without knowing too terribly much about Vim's internals thanks to GVim, and CLI junkies (like myself) can do pretty much the exact same thing mouse wielders do (and then some) without taking their hands off home row. =)

Putting Vim into a GUI and retaining the obscure key strokes is a little silly.

Not really, the power of Vim is it's command mode keystrokes. If you don't use them, go use notepad or whatever other people use.

None of these features are things that I haven't seen in other editors.

And yet no other editor offers the same set of features Vim does in such a small package. You can get smaller editors (usually other Vi clones) but they don't have the same feature set usually. And most other editors simply do not have the command line mode capabilities of Vim.

More than anything else, the discussion about using [ctrl-x][ctrl-o] made me think "Welcome to Emacs" Sure, all these things are big "wins" for vim users. Now just go see how long they've been in Emacs. Sheesh.

I've been using VIM 7 on windows for a while, but I was missing out on the tab and code completion features. Thx for the article. Now I've got one VIM open.

Got hooked on VIM years ago while a sysadmin. Got to say I don't agree with the obscure key stroke comment, the mouse is the devil not VIM's sweet key commands. Once you learn them you'll never leave the keyboard, its a lot faster.

The % command moves to a matching parenthesis or bracket or brace. As a result, d% will delete from here to the matching brace, and >% will indent (outdent) from here to the matching { } or { or }, useful e.g. for loops in C or Perl or awk.

Use :set showmatch (or :se sm) to make vi flash the cursor breifly on the opening paren when you type the closing one; it's useful for writers of prose as well as for programmers.

Putting vim into a gui and retaining the obscure key strokes is a little silly my arse. Vim is all about those silly key strokes, even when using the gui. If you don't want the silly key strokes, go with gnome-editor or something equally useless.

None of these features are things that I haven't seen in other editors. Even Windows editors are able to do most of this. Being able to check your spelling as you type is such an old feature that it shouldn't be vaunted in a review of an editor

Putting Vim into a GUI and retaining the obscure key strokes is a little silly. And the key strokes are obscure.

You obviously miss the point of Vim. If Wordpad is good enough for you, go forth and be happy. Why jump in and insult something you pretend to have knowledge of but miss the point of so widely?

I don't know if this is a good place to mention it, but Emacs has a major mode called "viper-mode" that is Vi. Amazingly, there is hardly any overlap between traditional Vi and Emacs command sets, so in Vi's insert mode it gives you the full power of both Emacs and Vi. Viper-mode is a very good implementation of Vi, with Emacs right there besides.

I use it for the gdb integration. Probably Vim has something better by now.

The parenthesis highlighting (appears to be default) can be annoying if your cursor is of a similar color as the highlights. You will have a hard time keeping track of your actual cursor. I found it here (googling of course) the :NoMatchParen part