Last Updated: February 25, 2016
·
815
· ohoushyar

vim Internal Perl Module Opener

Well actually 'gf' does pretty good however in some cases doesn't really work. For instance:

my $obj = Foo::Bar->new;

... hence, this is YET ANOTHER WAY of doing that ;) ...

Put these three lines in your vimrc and let your fingers rest a little bit:

map <Leader>omv y<C-w>np0ie lib/<esc>A.pm<esc>:%s/::/\//g<CR>:noh<CR>v$y:bd!<CR>:<C-r>0<CR>
map <Leader>om 0f<Space>eT<Space>vt;<Leader>omv
map <Leader>oms 0f<Space>eT<Space>vt<Space><Leader>omv

NOTE

It assumes your modules are in lib/ directory and you operate from your top-level directory of your project. Change lib to whatever you like if your lib is not in lib :) ...

What Next?

When you see:

use Foo::Bar;

... type

<Leader>om

When you see:

use Foo::Bar qw(baz);

... type

<Leader>oms

and when you see:

my $var = Foo::Bar->new;

... visual module name and type

<Leader>omv

Again feel free to change shortcuts if they are not convenient enough.

What do they do?

  • Visuals the module or asks you for
  • Opens a new window and paste it there
  • Replaces :: with /
  • Yanks it
  • Opens it uses register 0