Open Perl modules with vim

After reading about opening Perl module via name with vim, I realized it had a couple of (for me) limitations. First, I always operate from my top-level directory in a project, but that post doesn't prepend a lib/. Second, when I'm running a test suite, I see failure which might be from a module in the lib/ directory, but more often than not are in the t/lib/ directory. Since I keep all of my project directories identical, I can use one little bash function to handle this:

function vim {
  set -- "${@//:://}"
  module="lib/${@/%/.pm}"
  testclass="t/${@/%/.pm}"
  if [ -f $module ]; then
    command vim $module
  elif [ -f $testclass ]; then
    command vim $testclass
  else
    command vim "${@}"
  fi
}

So using it like this:

vim Veure::Foo::Bar::Baz

It will first look for lib/Veure/Foo/Bar/Baz.pm, and then look for t/lib/Veure/Foo/Bar/Baz.pm before finally giving up and just executing vim with whatever arguments I pass into it.

Improvements welcome.

4 Comments

another feature stolen from Padre :)

go vimers, go!

I use my Vim::Tag module to generate tags for package names, subroutine names and so on, so I can do:

    :ta Foo::Bar
    :ta my_subroutine

You can open vim at a tag with 'vi -t', and it's easy to set up bash completion for those tags.

http://search.cpan.org/dist/Vim-Tag/lib/Vim/Tag.pm

I've had this line in my aliases file for ages now:

vipm () { vi `perldoc -l $1 | sed 's/pod$/pm/' `}

Leave a comment

About Ovid

user-pic Have Perl; Will Travel. Freelance Perl/Testing/Agile consultant. Photo by http://www.circle23.com/. Warning: that site is not safe for work. The photographer is a good friend of mine, though, and it's appropriate to credit his work.