Bhaskar Karambelkar's Blog

New Features in Vim 7

 

Tags: vim7 vim omni complete


This is my first attempt to write a review of any kind, so please excuse any rookie mistakes. The entire review is written in EMACS…just kidding. The review was written in Vim 7.0 and screen shots were captured using ksnapshot and edited using krita.

Normally putting up screen shots of Vim is a ridiculous idea, but many of the new features have visual components (like pop-ups etc), so screen shots seem appropriate here.

If you have to ask what is Vim, then this review is not for you, as I am not going to explain what Vim is, rather this is an attempt to give a brief description of new features of Vim 7.0. So without further a do, let’s dive in to Vim 7.0.

New Features at a glance

  • getscript plugin
  • spell check
  • omni completion
  • Tabs
  • Undo branches
  • Internal Grep
  • Highlighting
  • Other notable improvements

getscript plugin

Scripts extend the functionality of Vim in many ways. Vim Official Site is the place where to get them, but until rel 7.0 there was no way of auto upgrading scripts to their latest version. That’s where the getscript plugin comes in handy. From within vim do ‘:GLVS’ and the script will download the latest version of the plugins already installed in your ‘$HOME/.vim’ directory. The script is not completely fool-proof and it requires some amount of preparation before it can get to work , but it is certainly step in the right direction.

Spell Check

Vim releases prior to 7.0 did support spell checking through external programs, but was clumsy and slow. Vim 7.0 has built in spell checking. It works out of box for English, all that is required is to issue an command ‘:setlocal spell spelllang=en_us’. Al though of little use to programmers, this will come in handy for documentation (You do document your code don’t you). Attached are a few screen shots to demonstrate Vim spell checking in action.

Spell checking in text mode

vim spell checking in text mode

Spell checking in gui mode

Vim spell checking in GUI mode

Sadly spell check did not work correctly while editing this document (how ironic). It would highlight mistakes only between link tags <a> and ignore the rest of the document. I had to rename the file with .txt extension to get spell check working. Also another annoyance is that if you are using a mouse to correct mistakes, you need to first left click on the misspelled word to move the cursor to that word, and then right click to activate the spelling menu, I would expect that right-clicking on a misspelled word should automatically move the cursor to it. Another option I couldn’t find in the GUI pop-up for spelling suggestions was the “change/ignore all”. I am sure the textmode working is much better.

Omni complete

Perhaps the most touted feature of all, initially called as intellisense, but renamed to omni complete due to trademark issues. This is a sort of smart complete primarily for programming/scripting languages.

The following languages are supported out of box, and the feature is extensible so adding support for other languages is trivial.

  • C
  • (X)HTML with CSS
  • JavaScript
  • PHP
  • Python
  • SQL
  • XML

The help pages on omni complete have detailed instructions on using this new feature. The key sequence to trigger omni complete is ^X^O (Control-X followed by Control-O).

There are already plenty of plugins available at www.vim.org for other languages. VJDE plugin adds IDE like functionality to Vim for editing Java/C/C++ code as well as add omni completion support for Java. cppomnicomplete adds omni complete support for C++. For XML it is possible to convert XML DTDs in to VIM XML data file, so that while editing an XML of that particular DTD, omni complete presents a list of only vaild elements/attributes as per the DTD.

One thing I noticed is that the speed of completion varies, it was quite fast for /Java/HTML but slow for PHP and somewhere in between for C.

Attached are a few screen shots of Omni Complete in action.

Omni Complete for C Omni Complete for html
omni complete for C omni complete for html
Omni Complete for Java Omni Complete for php
omni complete for java omni complete for php

Tabs

Another feature missing in Vim 6.x was tabs for editing multiple files. Although pre 7.0, Vim did support editing multiple files using the concept of buffers and vertical and horizontal splits, addition of tabs is welcome.This will definitely help in integrating Vim with other IDE environments such as Netbeans, Eclipse , Visual Studio etc.

One great feature about Vim tabs is the ease of moving from one tab to another. Simply in normal mode, type ‘[n]gt’ to move to the nth tab. Also all commands that work on windows work on tabs with ‘tab’ appended to them. e.g. ‘:tabnew’ .

Following is a screen shot for tabs.

tabs in action

Undo Branches

This is an interesting concept, and could become very useful. Traditionally any application has a single Undo/Redo Stack, so after undoing a lot of work if you make new changes, all the redo stack is lost. Vim creates backups of undos at regular interval, so that you can recreate the file as it looked at last branch. The ‘:undolist’ command shows all the undo branches.

How ever there are times when I want to undo a select steps but retain some changes. e.g. I make 10 changes, and undo 5, after that I want changes 9 and 10 redone, it is currently not possible and would require some sort of merge feature found in version control systems.

Internal Grep

Vim 7.0 comes built-in with it’s own grep, combined with the solid support for regular expressions, this is a handy feature for windows users who don’t have access to external grep command. The internal grep command is invoked by ‘:vimgrep’ and can recurse in to sub directories.

Highlighting

When ever the cursor moves over any of the following characters ‘<{[(’ it’s matching ‘>}])’ is highlighted. However this depends on a command getting executed every time the cursor moves and may need to disabled on slow terminals.

Also 2 more options ‘cursorline’ and ‘cursorcolumn’ have been added which enable highlighting of the line and column on which the cursor is present. Following is a screen shot with matching [] and cursorline enabled.

cursorline highlight

Other notable improvements

Here is a list of other notable improvements. This list is by no means exhaustive, and a full detailed documentation can be found in Vim help. ‘:help version7’ is your friend.

  • Support for printing multi-byte text
  • MzScheme interpreter support
  • Full 32 bit Unicode support
  • Remote file explorer with netrw plugin
  • Various New commands, vim scripting functions, search patterns
  • Syntax and Indent files for many more file types.
  • Lots and lots of improvements to existing functionality

Conclusion

In conclusion Vim 7.0 continues to build up on top of, what was an already solid 6.x series. I have been running 7.0 (alpha and beta) releases for a long time now and finally with release of 7.0 , it will surely replace all 6.x installation on all my boxes.

The new features of Vim will help to embed it in bigger IDEs such as Netbeans, Eclipse, Sun Studio etc. Thus programmers can have best of both worlds, the power of Vim and convenience of an IDE.

Notes

For this review Vim 7.0 was compiled from source on a Linux box. The reason behind compiling from source was to enable every possible feature , as against using the binary release which has only a limited set of features enabled. Following was the options passed to the ‘configure’ script.

./configure –prefix=/usr –sysconfdir=/etc –localstatedir=/var –enable-perlinterp –enable-pythoninterp –enable-tclinterp –enable-rubyinterp –enable-cscope –enable-multibyte –enable-xim –enable-fontset –enable-gui=auto –with-features=hugh