Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://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":



  • 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 How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-23 22:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found