Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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/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

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

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (14)
    As of 2014-07-31 19:19 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (251 votes), past polls