Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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/ 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 and ask.


In reply to Vim Settings for Perl by Smylers
in thread Desparately seeking a bilingual vim/Emacs expert by TheDamian

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2021-05-14 10:16 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (149 votes). Check out past polls.