Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Vim Settings for Perl

by Smylers (Pilgrim)
on Mar 23, 2005 at 11:01 UTC ( #441738=note: print w/ replies, xml ) Need Help??


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 tabstop=8 set expandtab set smarttab set shiftwidth=4 " or 2 or whatever set shiftround set autoindent

    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:

    setlocal isfname+=:
  • 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.

Smylers


Comment on Vim Settings for Perl
Select or Download Code
Re: Vim Settings for Perl
by runrig (Abbot) on Mar 23, 2005 at 21:50 UTC
    I like having perldoc output to a split window, and I wanted to output module documentation if you were on a 'use Module;' line, so I recently came up with this (my vim-foo could probably be better):
    function! PerlDoc() normal yy let l:this = @ if match(l:this, '^ *\(use\|require\) ') >= 0 exe ':new' exe ':resize' let l:this = substitute(l:this, '^ *\(use\|require\) *', "", "") let l:this = substitute(l:this, ";.*", "", "") let l:this = substitute(l:this, " .*", "", "") exe ':0r!perldoc -t ' . l:this exe ':0' return endif normal yiw exe ':new' exe ':resize' exe ':0r!perldoc -t -f ' . @ exe ':0' endfunction "Display docs for built-in functions when cursor is on function name "or for modules when cursor is on 'use' or 'require' line. map ,h :call PerlDoc()<CR>:set nomod<CR>:set filetype=man<CR>:echo "pe +rldoc"<CR>
    Updated. (I knew nothing about Vim programming before I started this...it took a couple of hours to come up with the first version of this, so comments, etc., welcome).
    Update: Added set nomod.
    Update: Added filetype, C-M=>CR, echo message
    Update: added -t

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://441738]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (13)
As of 2014-09-30 15:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (376 votes), past polls