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