views:

1194

answers:

11

There are a lot of threads pertaining to how to configure Vim/GVim for Perl development on PerlMonks.org. My purpose in posting this question is to try to create, as much as possible, an ideal configuration for Perl development using Vim/GVim. Please post your suggestions for .vimrc settings as well as useful plugins.

I will try to merge the recommendations into a set of .vimrc settings and to a list of recommended plugins, ftplugins and syntax files.

.vimrc settings

"Create a command :Tidy to invoke perltidy"
"By default it operates on the whole file, but you can give it a"
"range or visual range as well if you know what you're doing."
command -range=% -nargs=* Tidy <line1>,<line2>!
    \perltidy -your -preferred -default -options <args>

vmap <tab> >gv    "make tab in v mode indent code"
vmap <s-tab> <gv

nmap <tab> I<tab><esc> "make tab in normal mode indent code"
nmap <s-tab> ^i<bs><esc>

let perl_include_pod   = 1    "include pod.vim syntax file with perl.vim"
let perl_extended_vars = 1    "highlight complex expressions such as @{[$x, $y]}"
let perl_sync_dist     = 250  "use more context for highlighting"

set nocompatible "Use Vim defaults"
set backspace=2  "Allow backspacing over everything in insert mode"

set autoindent   "Always set auto-indenting on"
set expandtab    "Insert spaces instead of tabs in insert mode. Use spaces for indents"
set tabstop=4    "Number of spaces that a <Tab> in the file counts for"
set shiftwidth=4 "Number of spaces to use for each step of (auto)indent"

set showmatch    "When a bracket is inserted, briefly jump to the matching one"

syntax

plugins

ftplugins

CPAN modules

  • To be added

Debugging tools

I just found out about VimDebug. I have not yet been able to install it on Windows, but looks promising from the description.

+1  A: 

.vimrc:

" Allow :make to run 'perl -c' on the current buffer, jumping to 
" errors as appropriate
" My copy of vimparse: http://irc.peeron.com/~zigdon/misc/vimparse.pl

set makeprg=$HOME/bin/vimparse.pl\ -c\ %\ $*

" point at wherever you keep the output of pltags.pl, allowing use of ^-]
" to jump to function definitions.

set tags+=/path/to/tags
zigdon
What is pltags.pl? Is it better than ctags?
innaM
I think http://search.cpan.org/perldoc/Perl::Tags is based on it.
Sinan Ünür
Could you please explain if there are any advantages to using `pltags.pl` rather than `taglist.vim` w/ `ctags`?
Sinan Ünür
And vimparse.pl really works for you? Is that really the correct URL?
innaM
Yeah, I use vimparse quite a bit, and find it very useful. Is the URL not working for you?
zigdon
I've never tried using ctags for perl scripts - does it follow the modules used?
zigdon
@zigdon How is `vimparse.pl` different than Vim's quickfix mode? See http://vimdoc.sourceforge.net/htmldoc/quickfix.html
Sinan Ünür
@sinan it enables quickfix - all it does is reformat the output of perl -c so that vim parses it as compiler errors. The the usual quickfix commands work.
zigdon
@zigdon OK. Got it. One final question then: Have you used `Vi::QuickFix`?
Sinan Ünür
+3  A: 
" Create a command :Tidy to invoke perltidy.
" By default it operates on the whole file, but you can give it a
" range or visual range as well if you know what you're doing.
command -range=% -nargs=* Tidy <line1>,<line2>!
    \perltidy -your -preferred -default -options <args>
hobbs
+1  A: 

Here are a couple of my .vimrc settings. They may not be Perl specific, but I couldn't work without them:

set nocompatible        " Use Vim defaults (much better!) "
set bs=2                " Allow backspacing over everything in insert mode "
set ai                  " Always set auto-indenting on "
set showmatch           " show matching brackets "

" for quick scripts, just open a new buffer and type '_perls' "
iab _perls #!/usr/bin/perl<CR><BS><CR>use strict;<CR>use warnings;<CR>
innaM
+2  A: 

Look also at perl-support.vim (a Perl IDE for Vim/gVim). Comes with suggestions for customizing Vim (.vimrc), gVim (.gvimrc), ctags, perltidy, and Devel:SmallProf beside many other things.

fgm
I **hate** that one. The comments feature alone deserves a thorough 'rm -rf', IMHO.
innaM
I hate the fact that \$ is changed automatically to a "my $" declaration (same with \@ and \%). Does the author never use references or what?!
sundar
I take pieces of that one. If it were a man, you'd say about him, "He was only good for transplants..."
chiggsy
+3  A: 

From chromatic's blog (slightly adapted to be able to use the same mapping from all modes).

vmap ,pt :!perltidy<CR> 
nmap ,pt :%! perltidy<CR>

hit ,pt in normal mode to clean up the whole file, or in visual mode to clean up the selection. You could also add:

imap ,pt <ESC>:%! perltidy<CR>

But using commands from input mode is not recommended.

Ether
I seem to be missing something here: How can I type ,ptv without vim running perltidy on the entire file?
innaM
Ovid's comment (#3) seems offer a much better solution.
innaM
Three hours later: turns out that the 'p' in that mapping is a really bad idea. It will bite you when vim's got something to paste.
innaM
@Manni: select a region first: with the mouse if using gvim, or with visual mode (`v` and then use motion commands).
Ether
That's not what I meant. If ',pt' runs tidy on the complete file, why would vim wait for me to type 'v' if I am in visual mode? And how long?
innaM
@Manni: I just gave it a try: if you type `,pt`, vim waits for you to type something else (e.g. <cr>) as a signal that the command is ended. Hitting `,ptv` will immediately format the region. So I would expect that vim recognizes that there is overlap between the mappings, and waits for disambiguation before proceeding.
Ether
Thank you. That's what I call clever.
innaM
Try vmap ,pt <ESC>:'<,'>! perltidy<CR> instead.
Taurus Olson
+1  A: 

Here's an interesting module I found on the weekend: App::EditorTools::Vim. Its most interesting feature seems to be its ability to rename lexical variables. Unfortunately, my tests revealed that it doesn't seem to be ready yet for any production use, but it sure seems worth to keep an eye on.

innaM
+3  A: 

Perl Best Practices has an appendix on Editor Configurations. vim is the first editor listed.

Permanuno
+2  A: 

Andy Lester maintains the official Perl, Perl 6 and Pod support files for Vim on Github: http://github.com/petdance/vim-perl

daxim
Note that that link is already listed in the body of the question (look under **syntax**).
Sinan Ünür
+1  A: 

I have 2.

The first one I know I picked up part of it from someone else, but I can't remember who. Sorry unknown person. Here's how I made "C^N" auto complete work with Perl. Here's my .vimrc commands.

" to use CTRL+N with modules for autocomplete "
set iskeyword+=:
set complete+=k~/.vim_extras/installed_modules.dat

Then I set up a cron to create the installed_modules.dat file. Mine is for my mandriva system. Adjust accordingly.

locate *.pm | grep "perl5" | sed -e "s/\/usr\/lib\/perl5\///" | sed -e "s/5.8.8\///" | sed -e "s/5.8.7\///" | sed -e "s/vendor_perl\///" | sed -e "s/site_perl\///" | sed -e "s/x86_64-linux\///" | sed -e "s/\//::/g" | sed -e "s/\.pm//" >/home/jeremy/.vim_extras/installed_modules.dat

The second one allows me to use gf in Perl. Gf is a shortcut to other files. just place your cursor over the file and type gf and it will open that file.

" To use gf with perl "
set path+=$PWD/**,
set path +=/usr/lib/perl5/*,
set path+=/CompanyCode/*,   " directory containing work code "
autocmd BufRead *.p? set include=^use
autocmd BufRead *.pl set includeexpr=substitute(v:fname,'\\(.*\\)','\\1.pm','i')
J.J.
A: 

im programming in perl and here's my .vimrc file:
http://hermanningjaldsson.com/code/vim/.vimrc

Hermann Ingjaldsson
A: 

Hi

I find the following abbreviations useful

iab perlb  print "Content-type: text/html\n\n <p>zdebug + $_ + $' + $`  line ".__LINE__.__FILE__."\n";exit;
iab perlbb print "Content-type: text/html\n\n<p>zdebug  <C-R>a  line ".__LINE__.__FILE__."\n";exit;
iab perlbd do{print "Content-type: text/html\n\n<p>zdebug  <C-R>a  line ".__LINE__."\n";exit} if $_ =~ /\w\w/i;
iab perld print "Content-type: text/html\n\n dumper";use Data::Dumper;$Data::Dumper::Pad="<br>";print Dumper <C-R>a ;exit;

iab perlf foreach $line ( keys %ENV )<CR> {<CR> }<LEFT><LEFT>
iab perle while (($k,$v) = each %ENV) { print "<br>$k = $v\n"; }
iab perli x = (i<4) ? 4 : i;
iab perlif if ($i==1)<CR>{<CR>}<CR>else<CR>{<CR>}
iab perlh $html=<<___HTML___;<CR>___HTML___<CR>

You can make them perl only with

au bufenter *.pl iab xbug print "<p>zdebug ::: $_ :: $' :: $`  line ".__LINE__."\n";exit;
zzapper