When the common becomes too common

Here are just some quick helping things that accumulated and I wanted to document:

From my .zshrc

These are some simple shortcuts for common perldoc functions:

alias perlsource='perldoc -m'
alias perlwhere='perldoc -l'

From my .gvimrc

For a long time I hated to have to type the package name after creating a new file from hand. So I hacked up this little function to insert the part below the lib directory as package name.

function! InsertPackageFromFile()
perl << EO_MAP
    my ($row, $col) = $curwin->Cursor;
    my $file = $curbuf->Name;
    $file =~ s/\.pm$//;
    use List::MoreUtils qw( after );
    my $package = join '::',
        after { $_ eq 'lib' }
        split m{/},
        $file;
    my $line = join '',
        substr($curbuf->Get($row), 0, $col),
        $package,
        substr($curbuf->Get($row), $col);
    $curbuf->Set($row, $line);
EO_MAP
endfunction

map ,pp :call InsertPackageFromFile()<CR>

How about you?

Got any more Perl specific things to ease your daily routine?

No TrackBacks

TrackBack URL: http://www.catalyzed.org/mt/mt-tb.fcgi/40

2 Comments

| Leave a comment

Thanks for sharing this. My .bashrc contains almost identical stuff as it turns out:


export VIMPAGER="/usr/share/vim/vim72/macros/less.sh"
alias vless=$VIMPAGER
alias perlsrc="PAGER=$VIMPAGER /usr/bin/perldoc -t -m"
alias perlfunc='/usr/bin/perldoc -t -f'

The vim pager has the advantage of syntax highlighting while behaving like plain less.

My .vimrc also has this function:


function! ReplaceStringWithPerlHex(str)
let charlist = split(a:str, '\zs')
let newstr = ""
for c in charlist
let xc = printf("%04X", char2nr(c))
let xc2 = printf("%04X", char2nr(c[1]))
let hstr= "\\x{" . xc . "}"
let newstr .= hstr
if char2nr(c[1]) != 0
let hstr2 = "\\x{" . xc2 ."}"
let newstr .= hstr2
endif
endfor
exe "normal! i" . newstr
endfunction


which can be useful with something like:


vmap "zx:call ReplaceStringWithPerlHex(getreg("z"))a


Otherwise I use perl-support in vim, which does what your InsertPackageFromFile function achieves automatically ;)

Ah, and concerning vim and perl, the following links are quite useful too: [1], [2] and [3]

Sorry for taking so long to approve, I need something that electro-shocks me when I forget to read mails :)

The PAGER idea is excellent! Thanks you very much, I always forget that that's possible.

Leave a comment

All comments are moderated. Spammers don't waste your time

Sponsored By


Ionzero: Rescue your dev project.
OpenID accepted here Learn more about OpenID

Following

Not following anyone

Note to spammers: all comments are moderated. Don't waste your time