Technology Lab / Information Technology

Vim made easy: how to get your favorite IDE features in Vim

The open source Vim text editor offers a significant amount of power and …

The Vim text editor is a favorite of many programmers and system administrators. Although it provides an exceptional amount of power and flexibility, it can be somewhat intimidating for new users. Programmers who transition to Vim from a conventional integrated development environment (IDE) tend to find the paradigm shift a bit disorienting.

I often get e-mail from readers who are looking for ways to make Vim more developer-friendly. A common complaint is that the editor doesn't come with standard IDE features out of the box and it's not always clear how to configure it to provide equivalent functionality. The secret to unlocking Vim's real magic is to take advantage of its powerful plugin system and the large ecosystem of third-party scripts that offer editor augmentations for various tasks. To get you started, I have compiled a short list of useful tips and programming plugins for Vim that will make IDE refugees feel right at home.

Although Vim is largely designed around text-based interface idioms and is most effective when used accordingly, there are graphical shells available that make the program a bit more manageable for new users. Instead of running Vim in a terminal window, you might want to try GVim, the basic GUI version. It has configurable menus and toolbars that make the program's most essential features easily accessible with a mouse. It also lets you use native file dialogs and gives you the ability to resize buffer panes by clicking and dragging. GVim is available for both Linux and Windows. The equivalent for Mac OS X is MacVim, which provides a native Cocoa user interface, including menu integration.

GVim, with the default menu and toolbar configuration

The most frequent complaint that I see from new Vim users is that the buffer list is somewhat cumbersome and there is no easy way to see at a glance what files are open. There are several plugins that can address this issue by providing a special pane with a buffer list that can be used to easily navigate between open files. My favorite is MiniBufExplorer, which displays a list in a pane at the top of the window. When the MiniBufExplorer list is active, you can hit the tab key to rotate through items and you can select one by hitting enter or double-clicking.

MiniBufExplorer plugin

Many IDEs have a code navigation sidebar that displays the structure of your programming project and allows you to jump to a specific class or method by clicking. You can get this feature in Vim by using the popular Tag List plugin. The plugin requires the Exuberant Ctags utility, which it will use to analyze your code. The plugin's sidebar, which can be activated with the :Tlist command, will show you the classes and methods in the active buffer. As you open additional files and navigate to other buffers, they will be added to the list. In GVim, you can click a method name to jump to it. To do it with the keyboard, move the text cursor to the name of the method that you want to jump to and then hit enter.

TagList plugin demonstrated with a Python program

Automatic text completion is another common IDE feature that users want to bring with them to Vim. Support for this feature was introduced in Vim 7, via the Omnicompletion system. It's programmable, which means that it can be customized to work with various programming languages. There are even completion modules available for dynamic languages, such as Python and Ruby. The proper completion configurations are generally shipped as part of the default Vim package now, so you don't even have to do anything special to make it work. To invoke the completion menu, all you have to do is hit ctrl+x followed by ctrl+o. Then you can use ctrl+n and ctrl+p to navigate through the list of possible completions. As you rotate through the completion options, Vim will will show you contextual help information with method signatures and properties in a separate scratch buffer.

Vim's omnicompletion feature demonstrated with Python and the GTK+ library

There are many other ways that you can improve your Vim experience. The Vim wiki and script repository have a very extensive collection of third-party enhancements that you can use to add additional features. There are plugins that implement snippet systems, outlining tools, project management utilities, and a large number of other features. There are also many scripts that provide specialized enhancements for particular programming languages or frameworks. For example, there is an extremely popular script that will give you improved syntax highlighting and convenient navigation features for Ruby on Rails development.

There are also some script collections for the complete beginner that will make Vim behave almost exactly like a conventional text editor with standard keyboard shortcuts and simpler menus. You can use those to get you started if you are uncomfortable with Vim's cryptic keyboard commands.

The mutability of Vim allows it to be whatever the user desires. For those who don't have the time, expertise, or inclination to build the perfect Vim configuration by hand, the endless number of third-party scripts and plugins can get you most of the way there with very little effort.

Expand full story

You must to comment.

You May Also Like