A visual walk through of a couple of the new features in Vim 7.0

September 18, 2006
A very prominent personality once said, and I quote :
"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.

Other spelling related commands
:set spell - Turns on the spell checking
:set nospell - Turns off the spell checking (can be achieved using GUI too).

:]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.

45 comments:

  • Great tour and review. Always preferred Vim over Emacs.

  • "New Features in Vim 7" - "Paren Matching"?
    Where have you hibernated?

  • @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.

    Nice review. Enjoyed reading it.

  • 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.

  • Beautiful! but where are the rpms for RedHat EL4 and CentOS?


  • 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.

    The key for this is '%'.

  • Only in the wonderful world of *nix do we get reviews of text editors. And flame wars too.

    God, I love Unix.

    Vim Uber Alles!

  • 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.

    I am a happy Vim user from 1999 and never changed editor so far !

  • That "Omini completion" thingie is the worst thing I ever saw, how do I turn it off?

    Anyways, nice review, I just love VIm!

  • Nice to see you're back in the stoneage again!

  • It's funny the spellchecker thinks "GVim" is wrong but "Emacs" is good word. ;)

  • Thanks for the overview.

    Does it still have the option to :help uganda?

  • Perfect, short review of new features! THANKS!!

  • parenthesis : ()
    Brackets: []
    Braces: {}

    Vim knows them all.

  • 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?

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

  • Well, you could use the "Cream" set of scripts to turn GVim into a "Windoze-like-cua" program and still benefit from Vim features.

  • "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.

    BTW, Nice article.

  • 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.

    I side with the vim lovers.

  • Bill Anderson

    @ 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.

  • Don't hit escape. Hit ctrl-[. Same thing, but faster. Thanks.

  • 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.

  • Have you even worked with vi/vim before? Are you kidding me?

    If you think that "The idea of VIM as a graphical based text editor is anathema" then you obviously have not ever extensively used the editor, and have never gotten the point of it.

    "Obscure key strokes" = not having to move your hands from the home keys = more efficient editing.

  • Manu Anand

    Bram is an excellent programmer and an even better human being.
    Probably that is why he works for Google..

  • Is 'c' for correct a statement of state, or a request to change the state?

  • 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. =)

  • It isn't silly. I can use the same "keystokes" with vi and Vim on every platform I use (HP/UX, OSX, Windows).

  • Totally agree with the above comment. Visual Studio's editor for programming languages beats Vim any day...

  • 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.

    Neither of these features is new. The highlighting is new.

  • "That "Omini completion" thingie is the worst thing I ever saw, how do I turn it off?"

    DON'T use C-x C-o :)

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

    What are you smoking? It would be a different editor at that point...if you don't want to learn the commands use GEdit or some other dumbed down editor instead.

  • 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?

    Its all about choice and personal preference.

  • Don't hit escape. Hit ctrl-[. Same thing, but faster. Thanks.

  • It isn't silly. I can use the same "keystokes" with vi and Vim on every platform I use (HP/UX, OSX, Windows).

  • Hmm....can I do a:

    :later 1month

    ...and then save a months work ?

  • Joe

    How cool: Now all I need to do to write a program is open an empty file and hit ":later 4h"...

  • I hate to say this, but I write a lot of LaTeX and really enjoy using auctex with that other editor. Is there any way to add an auctex mode to vim? That would be so great.

  • 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.

  • Is there any way to add an auctex mode to vim?

    Yup. Go to vim.org, and you will find a version of AUCTeX for vim. It is not exactly like the Emacs counterpart, but really makes writing (La)TeX in vim enjoyable.

  • 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