in reply to
Desparately seeking a bilingual vim/Emacs expert
I gave a talk on Vim tips and tricks for Perl programmers at YAPC Europe in Belfast last year. Here's some of the useful config I mentioned.
Activate the Perl-filetype settings that come with Vim for many types of files, including Perl code:
filetype plugin on
You can put your own config that you want applying only to Perl files in ~/.vim/after/ftplugin/perl.vim; this will be applied after the system-wide settings (so can override them). You should use setlocal rather than set in such files, so that any settings don't 'leak out' to windows that are opened later for other types of files.
Indenting — I have these directly in my ~/.vimrc, applying to all filetypes:
filetype indent on " per-filetype config
set shiftwidth=4 " or 2 or whatever
Note that smarttab means that BkSpc at the beginning of the line will outdent by one level (not just delete a single space character), so that Tab and BkSpc together 'feel' like they're operating on tab characters, even though only spaces appear in your file. I leave tabstop set at 8, since that makes it more obvious when other people give you files with nasty tab characters in them!.
Navigating between files — put this in your ~/.vim/after/ftplugin/perl.vim and then when the cursor is on a module name (such as File::Temp) you can press Ctrl+W f to open the source (...wherever/lib/File/Temp.pm) of that module in a split window, or gf to load it in the current window:
Mappings — keystrokes to execute common commands. Save and check syntax with _c:
nnoremap <buffer> <silent> _c :w<Enter>:!perl -wc %<Enter>
Look up docs function under cusor with _f:
nnoremap <buffer> <silent> _f :perldoc -f <cword><Enter>
Look up docs for module under cusor with _m:
nnoremap <buffer> <silent> _m :perldoc <cword><Enter>
Tidy selected lines (or entire file) with _t:
nnoremap <buffer> <silent> _t :%!perltidy -q<Enter>
vnoremap <buffer> <silent> _t :!perltidy -q<Enter>
If you're using Vim's own gui (not running it in a terminal window) then running perldoc may try to invoke a pager that can't cope with the limited facilities available. I have these in my ~/.gvimrc to use Less and make it behave itself:
let $PAGER = 'less'
let $LESS = 'dQFe'
If anybody would like the full paper or slides, please mail me on Smylers@stripey.com and ask.