What are your suggestions for the ideal Vim configuration for Perl development?

There are many topics related to configuring Vim / GVim to develop Perl at PerlMonks.org . My goal in posting this question is to try to create, as far as possible, the perfect configuration for developing Perl using Vim / GVim. Please post your suggestions for .vimrc settings, as well as useful plugins.

I will try to combine the recommendations into a set of .vimrc parameters and a list of recommended plugins, ftplugins and syntax files.

.vimrc settings

 "Create a command :Tidy to invoke perltidy" "By default it operates on the whole file, but you can give it a" "range or visual range as well if you know what you're doing." command -range=% -nargs=* Tidy <line1>,<line2>! \perltidy -your -preferred -default -options <args> vmap <tab> >gv "make tab in v mode indent code" vmap <s-tab> <gv nmap <tab> I<tab><esc> "make tab in normal mode indent code" nmap <s-tab> ^i<bs><esc> let perl_include_pod = 1 "include pod.vim syntax file with perl.vim" let perl_extended_vars = 1 "highlight complex expressions such as @{[$x, $y]}" let perl_sync_dist = 250 "use more context for highlighting" set nocompatible "Use Vim defaults" set backspace=2 "Allow backspacing over everything in insert mode" set autoindent "Always set auto-indenting on" set expandtab "Insert spaces instead of tabs in insert mode. Use spaces for indents" set tabstop=4 "Number of spaces that a <Tab> in the file counts for" set shiftwidth=4 "Number of spaces to use for each step of (auto)indent" set showmatch "When a bracket is inserted, briefly jump to the matching one" 

syntax

plugins

ftplugins

CPAN Modules

Debugging Tools

I just found out about VimDebug . I have not yet been able to install it on Windows, but it looks promising from the description.

+56
vim perl configuration
Oct 15 '09 at 17:13
source share
12 answers

From the chromatic blog (slightly adapted to be able to use the same display from all modes).

 vmap ,pt :!perltidy<CR> nmap ,pt :%! perltidy<CR> 

press ,pt in normal mode to clear the entire file or in visual mode to clear the selection. You can also add:

 imap ,pt <ESC>:%! perltidy<CR> 

But using commands from input mode is not recommended.

+4
17 Oct '09 at 16:24
source share
 " Create a command :Tidy to invoke perltidy. " By default it operates on the whole file, but you can give it a " range or visual range as well if you know what you're doing. command -range=% -nargs=* Tidy <line1>,<line2>! \perltidy -your -preferred -default -options <args> 
+3
Oct 16 '09 at 0:35
source share

See also perl-support.vim (Perl IDE for Vim / gVim). Comes with suggestions for setting up Vim (.vimrc), gVim (.gvimrc), ctags, perltidy, and Devel: SmallProf along with many other things.

+3
Oct 17 '09 at 7:44
source share

Perl Best Practices has an application on Editor Configuration . vim is the first editor.

+3
Oct 20 '09 at 16:55
source share

Andy Lester and others support official Perl, Perl 6, and Pod support files for Vim on Github: https://github.com/vim-perl/vim-perl

+3
Dec 22 '09 at 9:33
source share

For ordering, I use the following: either \t to arrange the whole file, or I select several lines in shift+V mode, and then \t

 nnoremap <silent> \t :%!perltidy -q<Enter> vnoremap <silent> \t :!perltidy -q<Enter> 

Sometimes it is also useful to cancel the code. As indicated above, either for the entire file or for highlighting.

 nnoremap <silent> \D :.!perl -MO=Deparse 2>/dev/null<CR> vnoremap <silent> \D :!perl -MO=Deparse 2>/dev/null<CR> 
+2
Dec 07 '10 at 14:45
source share

.vimrc:

 " Allow :make to run 'perl -c' on the current buffer, jumping to " errors as appropriate " My copy of vimparse: http://irc.peeron.com/~zigdon/misc/vimparse.pl set makeprg=$HOME/bin/vimparse.pl\ -c\ %\ $* " point at wherever you keep the output of pltags.pl, allowing use of ^-] " to jump to function definitions. set tags+=/path/to/tags 
+1
Oct. 15 '09 at 19:25
source share

Here are a couple of my .vimrc settings. They cannot be Perl specific, but I could not work without them:

 set nocompatible " Use Vim defaults (much better!) " set bs=2 " Allow backspacing over everything in insert mode " set ai " Always set auto-indenting on " set showmatch " show matching brackets " " for quick scripts, just open a new buffer and type '_perls' " iab _perls #!/usr/bin/perl<CR><BS><CR>use strict;<CR>use warnings;<CR> 
+1
Oct 16 '09 at 8:20
source share

Here is an interesting module that I found this weekend: App::EditorTools::Vim . Its most interesting feature is its ability to rename lexical variables. Unfortunately, my tests showed that it is not yet ready for any use in production, but it seems worth paying attention to.

+1
Oct 19 '09 at 8:57
source share

I have 2.

The first thing I know, I took part of it from someone else, but I don’t remember who. Sorry, unknown. Here, as I did "C ^ N" automatic full work with Perl. Here are my .vimrc commands.

 " to use CTRL+N with modules for autocomplete " set iskeyword+=: set complete+=k~/.vim_extras/installed_modules.dat 

Then I create cron to create the installed_modules.dat file. Mine is for my mandriva system. Set accordingly.

 locate *.pm | grep "perl5" | sed -e "s/\/usr\/lib\/perl5\///" | sed -e "s/5.8.8\///" | sed -e "s/5.8.7\///" | sed -e "s/vendor_perl\///" | sed -e "s/site_perl\///" | sed -e "s/x86_64-linux\///" | sed -e "s/\//::/g" | sed -e "s/\.pm//" >/home/jeremy/.vim_extras/installed_modules.dat 

The second allows me to use gf in Perl. Gf is a shortcut to other files. just place the cursor over the file and type gf and it will open that file.

 " To use gf with perl " set path+=$PWD/**, set path +=/usr/lib/perl5/*, set path+=/CompanyCode/*, " directory containing work code " autocmd BufRead *.p? set include=^use autocmd BufRead *.pl set includeexpr=substitute(v:fname,'\\(.*\\)','\\1.pm','i') 
+1
Feb 17 '10 at 21:35
source share

I find the following abbreviations useful

 iab perlb print "Content-type: text/html\n\n <p>zdebug + $_ + $' + $` line ".__LINE__.__FILE__."\n";exit; iab perlbb print "Content-type: text/html\n\n<p>zdebug <CR>a line ".__LINE__.__FILE__."\n";exit; iab perlbd do{print "Content-type: text/html\n\n<p>zdebug <CR>a line ".__LINE__."\n";exit} if $_ =~ /\w\w/i; iab perld print "Content-type: text/html\n\n dumper";use Data::Dumper;$Data::Dumper::Pad="<br>";print Dumper <CR>a ;exit; iab perlf foreach $line ( keys %ENV )<CR> {<CR> }<LEFT><LEFT> iab perle while (($k,$v) = each %ENV) { print "<br>$k = $v\n"; } iab perli x = (i<4) ? 4 : i; iab perlif if ($i==1)<CR>{<CR>}<CR>else<CR>{<CR>} iab perlh $html=<<___HTML___;<CR>___HTML___<CR> 

You can do them perl only with

 au bufenter *.pl iab xbug print "<p>zdebug ::: $_ :: $' :: $` line ".__LINE__."\n";exit; 
+1
Sep 23 '10 at 9:41
source share

The most useful are

  • Perl filetype pluging (ftplugin) - this color code of various code elements
  • Creating the check-syntax-before-saving "W" command without allowing you to save bad code (you can override the normal "w").

Installing its plugins is a bit tricky, as the vim (and linux) version puts the plugins in different places. Mine are in ~ / .vim / after /

my.vimrc below.

 set vb set ts=2 set sw=2 set enc=utf-8 set fileencoding=utf-8 set fileencodings=ucs-bom,utf8,prc set guifont=Monaco:h11 set guifontwide=NSimsun:h12 set pastetoggle=<F3> command -range=% -nargs=* Tidy <line1>,<line2>! \perltidy filetype plugin on augroup JumpCursorOnEdit au! autocmd BufReadPost * \ if expand("<afile>:p:h") !=? $TEMP | \ if line("'\"") > 1 && line("'\"") <= line("$") | \ let JumpCursorOnEdit_foo = line("'\"") | \ let b:doopenfold = 1 | \ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) | \ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 | \ let b:doopenfold = 2 | \ endif | \ exe JumpCursorOnEdit_foo | \ endif | \ endif " Need to postpone using "zv" until after reading the modelines. autocmd BufWinEnter * \ if exists("b:doopenfold") | \ exe "normal zv" | \ if(b:doopenfold > 1) | \ exe "+".1 | \ endif | \ unlet b:doopenfold | \ endif augroup END 
0
May 03 '13 at 12:45
source share



All Articles