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

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I started to write this .vimrc file because I wanted my programs to use 4-space (actual spaces!) identation.

That was a simple need, but, after a quick research, I found many features that made Perl programming more enjoyable in Vim.

Without more delay, here's my .vimrc file:

" use visual bell instead of beeping set vb " incremental search set incsearch " syntax highlighting set bg=light syntax on " autoindent autocmd FileType perl set autoindent|set smartindent " 4 space tabs autocmd FileType perl set tabstop=4|set shiftwidth=4|set expandtab|set + softtabstop=4 " show matching brackets autocmd FileType perl set showmatch " show line numbers autocmd FileType perl set number " check perl code with :make autocmd FileType perl set makeprg=perl\ -c\ %\ $* autocmd FileType perl set errorformat=%f:%l:%m autocmd FileType perl set autowrite " dont use Q for Ex mode map Q :q " make tab in v mode ident code vmap <tab> >gv vmap <s-tab> <gv " make tab in normal mode ident code nmap <tab> I<tab><esc> nmap <s-tab> ^i<bs><esc> " paste mode - this will avoid unexpected effects when you " cut or copy some text from one window and paste it in Vim. set pastetoggle=<F11> " comment/uncomment blocks of code (in vmode) vmap _c :s/^/#/gi<Enter> vmap _C :s/^#//gi<Enter> " my perl includes pod let perl_include_pod = 1 " syntax color complex things like @{${"foo"}} let perl_extended_vars = 1 " Tidy selected lines (or entire file) with _t: nnoremap <silent> _t :%!perltidy -q<Enter> vnoremap <silent> _t :!perltidy -q<Enter> " Deparse obfuscated code nnoremap <silent> _d :.!perl -MO=Deparse 2>/dev/null<cr> vnoremap <silent> _d :!perl -MO=Deparse 2>/dev/null<cr>

Most of the features are self-evident when you open your next perl script. Other features deserve some comments:

  • Use ":make" to check your code: it will call "perl -c" to verify your code and, if there are any erros, the cursor will be positioned in the offending line.
  • Get rid of the Ex mode: I often entered in Ex mode when I wanted to type ":q"...
  • Indent code with tabs: Use "v" to select a region, or indent line by line in normal mode. (Use shift-tab to unindent.)
  • Press F11 to toggle the "paste mode", disabling autoindent so that any text you paste won't loose its original layout.
  • UPDATE: added some hints from the comments.

I hope you'll find those tricks useful!


In reply to .vimrc for perl programmers by nferraz

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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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 exploiting the Monastery: (11)
    As of 2015-07-02 10:06 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (33 votes), past polls