I am now on Twitter! Meet me on Twitter here (my nick is pkrumins.)
Or on Google Buzz and Facebook.

This 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!
Did you like this post? Subscribe here:
If you really enjoyed the post, I'd appreciate a gift from my geeky Amazon book wishlist. Books would make me more educated and I could write even better posts. Thanks! :)

|
|
|


November 6th, 2009 at 12:00 am
:e file
will switch to another file, and
:e#
will switch back to the previous file, without any plugins. (that’s even in vi, rather than just vim.)
November 6th, 2009 at 8:32 am
[…] Vim Plugins You Should Know About, Part V: a.vim […]
November 6th, 2009 at 11:08 am
%:r is replaced with the currently edited filename minus the extension, so you can use :e %:r.h and :e %:r.c to switch quickly (use :tabe instead of :e to edit in a new tab). Of course those could be bound to keys or commands, but is quite short on its own.
November 7th, 2009 at 12:52 am
a.vim is really handy, I’ve been using it for years. I have also developed my own plugin for TDD, which you may find useful:
http://github.com/johnsyweb/dotfiles/blob/master/.vim/plugin/toggle_unit_tests.vim
November 8th, 2009 at 6:31 pm
[…] plugins: a.vim lets you switch between .c and .h files with a single […]
November 9th, 2009 at 1:12 am
[…] plugins: a.vim lets you switch between .c and .h files with a single […]
November 9th, 2009 at 8:58 pm
[…] Vim Plugins You Should Know: a.vim : http://www.catonmat.net/blog/vim-plugins-a-vim/ […]
November 9th, 2009 at 8:59 pm
[…] #Vim Plugins You Should Know: a.vim : http://www.catonmat.net/blog/vim-plugins-a-vim/ […]
December 2nd, 2009 at 9:47 pm
I’m a python guy, so I don’t really need this, but I really enjoy this series. Thanks a lot. Surround is awesome! (:
December 9th, 2009 at 1:20 am
I use Increment.vim
a.vim (alternate)
doxygen.vim (for adding Doxygen comments for C++ programs)
ProjectExplorer (if working on Linux) - it doesn’t work on windows :-(
January 18th, 2010 at 2:59 pm
[…] Part V: a.vim - quickly change between source and header files (.c/.h). […]
January 18th, 2010 at 4:50 pm
I use :e %
March 7th, 2010 at 5:01 am
I was momentarily stymied by the install procedures until I determined a.vim should be put in the ~/vimfiles/plugin directory on windows. (The error I was getting was (E471: Argument required”)
March 7th, 2010 at 8:38 am
Brent, oh, right. I have a mistake in the article. It’s ~/vimfiles/plugin.