Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: .vimrc for perl programmers

by Codon (Friar)
on Mar 31, 2006 at 08:40 UTC ( #540411=note: print w/replies, xml ) Need Help??

in reply to .vimrc for perl programmers

These are all great. Because of all of your autocmd lines, I'd suggest creating a function to be called:

function! Perl() " autoindent set autoindent set smartindent " 4 space tabs set tabstop=4 set shiftwidth=4 set expandtab set softtabstop=4 " show matching brackets set showmatch " show line numbers set number " check perl code with :make set makeprg=perl\ -c\ %\ $* set errorformat=%f:%l:%m set autowrite endfunction " Call Perl() when you open a Perl file autocmd FileType perl call Perl()

Now, I have some things to add that I really like. I like cindent because I can control the indentation style with some rules. I can also add to or remove from the list of indentation keywords:

" restore defaults (incase I :e or :sp) set cinkeys& " don't go to column zero when # is the first thing on the line set cinkeys-=0# " restore defaults set cinwords& " add Perl-ish keywords set cinwords+=elsif,foreach,sub,unless,until set cinoptions& " I don't rememer these OTTOMH; :help cinoptions to learn more set cinoptions+=+2s,(1s,u0,m1 set cindent

Then sometimes I want <Tab> to indent (insert a tab), sometimes I want it to do word autocompletion (like bash). So, I stole^H^H^H^H^Hborrowed this from a former coworker:

" SmartTab wrapper function! SmartTab() let col = col('.') - 1 if !col || getline('.')[col - 1] !~ '\k' return "\<tab>" else return "\<c-p>" endif endfunction " turn on SmartTabs inoremap <tab> <c-r>=SmartTab()<cr>

Then a current coworker found/modified/developed (not totally sure which) this nifty status bar which tells you what function (sub) you are in:

set statusline=%f%{CurrSubName()}\ %m%h%r\ %=%25(%-17(%l\,%c%V%)\ %p +%%%) set laststatus=2 set maxfuncdepth=250 function! CurrSubName() let g:subname = "" let g:subrecurssion = 0 " See if this is a Perl file let l:firstline = getline(1) if ( l:firstline =~ '#!.*perl' || l:firstline =~ '^package ' ) call GetSubName(line(".")) endif return g:subname endfunction function! GetSubName(line) let l:str = getline(a:line) if l:str =~ '^sub' let l:str = substitute( l:str, " *{.*", "", "" ) let l:str = substitute( l:str, "sub *", ": ", "" ) let g:subname = l:str return 1 elseif ( l:str =~ '^}' || l:str =~ '^} *#' ) && g:subrecurssion == + 1 return -1 elseif a:line > 2 let g:subrecurssion = g:subrecurssion + 1 if g:subrecurssion < 190 call GetSubName(a:line - 1) else let g:subname = ': <too deep>' return -1 endif else return -1 endif endfunction
Finally, everyone has their way to do compiler checks, block comment/uncomment, etc. Mine are:
map !! :!perl -c %<CR> map ## :s/^/#/<CR> map !# :s/^#//<CR>

These are, of course, all part of my Perl() function. I have others for toggling list, paste, number, and wrap. And since I use split windows I map Ctrl+[arrow keys] to move between panes. This one is tricky because it really depends on terminal settings; I'm still working on some bugs with it.

Ivan Heffner
Sr. Software Engineer, DAS Lead, Inc.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://540411]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2017-07-22 22:18 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (342 votes). Check out past polls.