I do lots of Perl, some PHP.
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
"============================================================================
" General settings
"----------------------------------------------------------------------------
set nocompatible " nocp: turn off vi compatibility
set undolevels=1000 " ul: lots and lots of undo
set history=50 " hi: size of :command history
set modelines=20
set modeline " ml: Turn on modelines
set ai " always set autoindenting on
set backup " keep a backup file
set ruler " show the cursor position all the time
filetype on
syntax on
"============================================================================
" Colors
"----------------------------------------------------------------------------
set t_Sf=[3%dm " set foreground (?)
set t_Sb=[4%dm " set background (?)
"============================================================================
" Presentation
"----------------------------------------------------------------------------
set shortmess=aIoO " sm: really short messages, don't show intro
set showmode " smd: show the current input mode
set more " more: page on extended output
set errorbells " eb: ring bell on error messages
set novisualbell " novb: turn of visual bell
set noequalalways " noea: don't always keep windows at equal size
set splitbelow " sb: splitted window appears below current one
"============================================================================
" Statusline, Ruler
"----------------------------------------------------------------------------
set laststatus=2 " ls: always put a status line
set statusline=%([%-n]%y\ %f%M%R%)\ %{CurrSubName()}\ %=\ %(%l,%c%V\ %P\ [0x%02.2B]%)
set maxfuncdepth=1000 " Need more depth for sub names
"============================================================================
" Filename Autocompletion
"----------------------------------------------------------------------------
set wildchar=<Tab> " wc: tab does autocompletion
set wildmode=longest,list " wim: bash-style autocompletion
" wig: when autocompleting, ignore certain files
set wildignore=*~,#*#,*.sw?,*.o,*.class,*.java.html,*.cgi.html,*.html.html,.viminfo,*.pdf,*.mp3
"============================================================================
" Search and Replace
"----------------------------------------------------------------------------
set incsearch " is: show partial matches as search is entered
set hlsearch " hls: highlight search patterns
"set ignorecase " Ignore case distinction when searching
"set smartcase " ... unless there are capitals in the search string.
"set nowrapscan " Don't wrap to top of buffer when searching
"============================================================================
" Tab standards
"----------------------------------------------------------------------------
set softtabstop=4
set shiftwidth=4
set shiftround " Shift to the next round tab stop
set expandtab
" Make p in Visual mode replace the selected text with the "" register.
vnoremap p <Esc>:let current_reg = @"<CR>gvs<C-R>=current_reg<CR><Esc>
behave xterm
if &term == "xterm"
let &term = "xtermc"
" Restore the screen when we're exiting
set rs
set t_ti=7[r[?47h
set t_te=[?47l8
endif
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
"============================================================================
" Autocommands
"----------------------------------------------------------------------------
" For all text files set 'textwidth' to 78 characters.
au FileType text setlocal tw=78
" *.t files are Perl test files
au FileType pl,pm,t set filetype=perl
au FileType perl set makeprg=perl\ -c\ %\ $*
au FileType perl set errorformat=%f:%l:%m
au FileType perl set autowrite
au FileType perl call PerlMode()
au FileType perl :noremap K :!perldoc <cword> <bar><bar> perldoc -f <cword><cr>
" http://vimdoc.sourceforge.net/htmldoc/vimfaq.html
" 5.5. How do I configure Vim to open a file at the last edited location?
" Vim stores the cursor position of the last edited location for each buffer
" in the '"' register. You can use the following autocmd in your .vimrc or
" .gvimrc file to open a file at the last edited location:
au BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
au BufNewFile,BufRead *.pl,*.pm,*.t setf perl
au BufNewFile,BufRead *.pmc,*.ops setf c
au BufNewFile,BufRead *.tt,*.ttml setf tt2html
au BufNewFile,BufRead *.phpt setf php
au FileType text call TextMode()
au FileType mail call TextMode()
au FileType vim set iskeyword+=. iskeyword+=/ iskeyword+=~
let perl_fold=1
let perl_include_pod=1
" syntax color complex things like @{${"foo"}}
let perl_extended_vars = 1
au BufNewFile * silent! 0r ~/.vim/templates/%:e.tpl
set showmatch " show matches on parens, bracketc, etc.
set matchpairs+=<:>
" Folding
set foldmethod=marker
set nofoldenable
set background=dark
set autoindent
set cindent
" Set visible tabs and trailing spaces
set list listchars=tab:\|-,trail:.
set tags=./tags,./Tags,tags,~/parrot/tags
set backspace=indent,eol,start
" make tab in visual mode indent code
vmap <tab> >gv
vmap <s-tab> <gv
" Stop the annoying behavior of leaving comments on far left
set fo+=r
" Don't do the auto-highlighting
" From :help matchparen
let loaded_matchparen=1
" Suffixes that get lower priority when doing tab completion for filenames.
" These are files we are not likely to want to edit or read.
set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc,.ln
" Paths to check for loading files with "gf"
set path=.,./Include
"============================================================================
" Abbreviations
"----------------------------------------------------------------------------
abbreviate udd {use Data::Dumper; local $Data::Dumper::Sortkeys=1;
print Dumper()}hi
"============================================================================
" Key remapping
"----------------------------------------------------------------------------
" SQL Formatter mappings from
" http://www.vim.org/scripts/script.php?script_id=492
" Each <silent> means a backslash I guess
vmap <silent>sf <Plug>SQLU_Formatter<CR>
nmap <silent>scl <Plug>SQLU_CreateColumnList<CR>
nmap <silent>scd <Plug>SQLU_GetColumnDef<CR>
nmap <silent>scdt <Plug>SQLU_GetColumnDataType<CR>
nmap <silent>scp <Plug>SQLU_CreateProcedure<CR>
"============================================================================
" Functions
"----------------------------------------------------------------------------
function! TextMode() " Stolen from David Hand
set nocindent " nocin: don't use C-indenting
set nosmartindent " nosi: don't "smart" indent, either
set autoindent " ai: indent to match previous line
set noshowmatch " nosm: don't show matches on parens, brackets, etc.
set comments=n:>,n:#,fn:- " com: list of things to be treated as comments
set textwidth=72 " tw: wrap at 72 characters
set formatoptions=tcrq " fo: word wrap, format comments
set dictionary+=/usr/local/dict/* " dict: dict for word completion
set complete=.,w,b,u,t,i,k " cpt: complete words
endfunction
function! PerlMode() " Stolen from David Hand
set shiftwidth=4 " sw: a healthy tab stop
set textwidth=72 " tw: wrap at 72 characters
set autoindent " ai: indent to match previous line
set cindent " cin: Use C-indenting
set cinkeys=0{,0},!^F,o,O,e " cink: Perl-friendly reindent keys
set cinoptions=t0,+4,(0,)60,u0,*100 " cino: all sorts of options
set cinwords=if,else,while,do,for,elsif,sub
set comments=n:# " com: Perlish comments
set formatoptions=crql " fo: word wrap, format comments
set nosmartindent " nosi: Smart indent useless when C-indent is on
set showmatch " show matches on parens, bracketc, etc.
endfunction
" From http://www.perlmonks.org/?node_id=540411
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