Vim Plugins, surround.vimThis is the fifth post in the article series "Vim Plugins You Should Know About". This time I am going to introduce you to a nifty plugin called "a.vim".

A.vim allows you to quickly switch between related source code files. For example, if you're programming in C, you can alternate between source.c and the corresponding header source.h by just typing :A.

It saves you only a few seconds every time you use it, but don't forget that these seconds can add up to hours during several weeks.

This plugin was written by Mike Sharpe.

For the introduction of this article series see part one - surround.vim.

Other bindings in a.vim

Besides the " :A " command that alternates between source files in the same buffer, a.vim also defines several other commands:

  • :AS -- alternate in a horizontal split,
  • :AV -- alternate in a vertical split, and
  • :AT -- alternate in a new tab.

The author of the plugin also defines the command " :IH ", which opens the file under cursor, but it's really unnecessary because "gf" already does that.

Extending a.vim

By default a.vim defines alternation for the following languages:

  • C -- .c <-> .h,
  • C++ -- .c / .cpp / .cxx / .cc <-> .h / .hpp,
  • lex and yacc -- .l / .lex / .lpp <-> .y / .ypp / .yacc,
  • ASP.NET -- .aspx <-> .aspx.cs / .aspx.vb

The alternation can be extended to other extensions by defining the following variable in your .vimrc:

let g:alternateExtensions_foo = "bar,baz"

This will set up alternation between .foo, .bar and .baz files.

How to install a.vim?

To get the latest version:

  • 1. Download a.vim.
  • 2. Put a.vim in ~/.vim/plugin (on Unix/Linux) or ~\vimfiles\plugin (on Windows).
  • 3. Download alternate.txt from the same page.
  • 4. Put alternate.txt in a.vim in ~/.vim/doc (on Unix/Linux) or ~/vimfiles/doc (on Windows).
  • 5. Run :helptags ~/.vim/doc (on Unix/Linux) or :helptags ~/vimfiles/doc (on Windows) to rebuild the tags file (so that you can read :help alternate.)
  • 6. Restart Vim.

I have mapped the :A command to " ,a ". You can also map it to the same combination by putting "map ,a :A<CR>" in your .vimrc file.

Have Fun!

Have fun with this plugin and until next time!