What cool stuff are y'all doing with Vim and Perl and how can we get
the rest of the programmer public to take advantage of those marvelous
advances you're using?
xoxo,
Andy
--
Andy Lester => an...@petdance.com => www.theworkinggeek.com => AIM:petdance
I generally assume that my use of Vim is far from state of the art. I
don't look over other users' shoulders often enough to pick up juicy
tips. But here's what I do:
I have my home directory in svn[1] and check it out on MacOS, Linux,
Solaris, *BSD and Cygwin - so I try to keep my customisations as cross
platform as possible. If you follow the link to the svn repo below
you'll notice, for example, that my .gvimrc has all sorts of tweaks so
that I get the same font size in MacVim and GVim.
I generally run console Vim and usually have multiple windows open in
Vim[2] so one of my biggest time savers is:
noremap <C-Up> <esc><C-w>k<C-w>_
noremap <C-Down> <esc><C-w>j<C-w>_
noremap <C-Left> <esc><C-w>h<C-w>_
noremap <C-Right> <esc><C-w>l<C-w>_
They bind Ctrl+Left/Right/Up/Down to switch to the window in that
direction and maximise it.
For every language for which I can find a decent source code
prettifier I have a binding F2 -> tidy source. For Perl that's
Perl::Tidy of course. I don't format anything manually if I can help
it and using languages for which there is no prettifier has become a
major pain as a result.
I have hooks so that when I create a new .pm file it attempts to guess
the package name from the path and gives me a boilerplate module with
the name filled in.
I have F5 bound to this script[3]. If the cursor is in a string
literal it cycles the quoting between single and double quotes (and
backwacks any embedded quotes to suit). If the string happens to be a
valid bareword it also cycles through unquoted - and if the cursor is
outside a string but on a valid bareword it will be quoted.
So I can
"foo" => bar # cursor in "foo", F5
'foo' => bar # F5 again
foo => bar # F5 again
"foo" => bar
I just started playing with that. The philosophy behind it is slightly
more grandiose than that example suggests. I wanted to have a FIX
THIS! key which I can hit whenever something doesn't look quite right
and have it, based on context, cycle through a number of alternative
representations. For example if the cursor is on 'for' or 'foreach'
hitting F5 should cycle through those alternatives, Similarly if/
unless, while/until, &&/and, ||/or.
One of the criteria for success will be whether I start instinctively
stabbing frantically at F5 when confronted with anything I don't like
- even if it's not written in Perl and has no chance of working :)
There's other stuff - most of which can be gleaned from [1].
Incidentally I suspect my Vim coding style is painfully naive -
criticism is welcome :)
[1] https://svn.hexten.net/andy/home
[2] http://hexten.net/junk/vim.png
[3] https://svn.hexten.net/andy/home/.vim/include/flipquotes.vim
--
Andy Arms
trong, Hexten
Kiffin Gish <Kiffi...@planet.nl>
Gouda, The Netherlands
> map ,pc <Esc>:! perl -c %<CR>
>
> Would be nice if I could get it to output to a separate buffer, but my
> vim script-fu isn't up there yet :)
Why don't you make that a ticket in the tracking system? Maybe
someone will take care of it for you.
xoa
You should be able to unset that mapping by adding the following to
your .vimrc file (or better yet ~/.vim/ftplugin/perl.vim):
unimap \@
The only potential problem I see is making sure that this is run after
the perl-support plug-in is loaded.
-Mark
I'm not sure how to open the output in another window, but if you set
"perl -c" as your compiler you can use the :make command to check
syntax and then use :cn and :cp to move forward and back to each
error. Here are the key lines from the rc files:
CompilerSet makeprg=perl\ -Ilib\ -c\ %
CompilerSet errorformat=
\%-G%.%#had\ compilation\ errors.,
\%-G%.%#syntax\ OK,
\%m\ at\ %f\ line\ %l.,
\%+A%.%#\ at\ %f\ line\ %l\\,%.%#,
\%+C%.%#
compiler perl
nmap <buffer> ,pc :w<cr>:make<cr>
I actually use Christian Robinson's perl.vim compiler file which is a
bit more complete (google for "Christian J. Robinson perl.vim" and
save it as ~/.vim/compiler/perl.vim).
-Mark
For me, I add library paths to it or give options for tainting:
map ,pc :!perl -Mlib=lib -c %<CR>
map ,pcb :!perl -Mblib -c %<CR>
map ,pC :!perl -tc %<CR>
Other perl stuff:
* Running code (why I don't do the same Mlib/Mblib stuff as above, I
don't know.)
map ,pr :!perl %<CR>
map ,pR :!perl -t %<CR>
map ,pd :!perl -d %<CR>
* Run current (.t) file through "Build test"
map ,bt :!perl Build test verbose=1 --test_files=%<CR>
* Various ways to start of a blank file with some boilerplate
map ,pl ggI#!/usr/bin/env perl<CR>use strict;<CR>use warnings;<CR>use
XDG;<CR><ESC>
map ,pmm ggIpackage PACKAGE;<CR>use strict;<CR>use warnings;<CR><ESC>3kw
map ,pb iuse Benchmark qw( cmpthese :hireswallclock );<CR><CR>my
$count = 100_000;<CR>cmpthese( $count, {<CR>'Name1' => sub {
},<CR>});<CR><ESC>
* block add/remove comments
vmap ,ic :s/^/#/g<CR>:let @/ = ""<CR>
vmap ,rc :s/^#//g<CR>:let @/ = ""<CR>
map ,ic :s/^/#/g<CR>:let @/ = ""<CR>
map ,rc :s/^#//g<CR>:let @/ = ""<CR>
* increment decrement test count (only on a "plan tests =>" line, though)
map <silent> ,at m` :silent ?plan tests =><CR>3w<C-A>,/``
map <silent> ,rt m` :silent ?plan tests =><CR>3w<C-X>,/``