Skip to content

Instantly share code, notes, and snippets.

@evilchili
Created November 5, 2010 17:15
Show Gist options
  • Save evilchili/664466 to your computer and use it in GitHub Desktop.
Save evilchili/664466 to your computer and use it in GitHub Desktop.
vimrc for perl/mason/js editing
" Embedded() is a function that will parse a text buffer
" looking for embedded vim commands, and execute them.
" Call it with a range of lines to check, eg to check the whole
" file:
"
" :%call Embedded()
"
" Commands should be prefixed by the sequence :vim: .
"
function Embedded() range
let n = a:firstline
while n <= a:lastline
let l = getline(n)
let p = stridx(l,':vim:')
if p > -1
let p = p + 5
let c = strpart(l,p)
execute c
endif
let n = n + 1
endwhile
endfunction
" call Embedded() whenever a file is loaded and
" parse the entire file. You may not want to do
" this for *; maybe just your src tree or certain
" file types or something.
autocmd BufWinEnter * %call Embedded()
" Create nested folds on custom expressions, based
" on the current buffer's filetype or syntax.
"
let g:foldlevel = 0
let g:foldstartexpr = ''
let g:foldendexpr = ''
function GetCustomFold()
if getline(v:lnum) =~ g:foldstartexpr
let g:foldlevel = g:foldlevel + 1
return ">".g:foldlevel
elseif getline(v:lnum) =~ g:foldendexpr
let thislevel = g:foldlevel
let g:foldlevel = g:foldlevel - 1
return "<".thislevel
else
return g:foldlevel
endif
endfunction
function SetFoldType()
let f = &filetype ? &filetype : &syntax
if f == 'mason'
let g:foldstartexpr = '^\s*<\(script\|style\|%init\|%attr\|%once\|%args\|%flags\|%shared\|%def\)[^>]*>\s*$'
let g:foldendexpr = '^\s*</\(script\|style\|%init\|%attr\|%once\|%args\|%flags\|%shared\|%def\)[^>]*>\s*$'
elseif f == 'perl'
let g:foldstartexpr = '^sub.*{\s*$'
let g:foldendexpr = '^}\s*$'
elseif f == 'javascript'
let g:foldstartexpr = '^function.*{\s*$'
let g:foldendexpr = '^}\s*$'
else
return
endif
setlocal foldexpr=GetCustomFold()
setlocal foldmethod=expr
endfunction
autocmd BufWinEnter * %call SetFoldType()
function SetPerlIDE()
" check perl code with :make
setlocal makeprg=perl\ -c\ %\ $*
setlocal errorformat=%f:%l:%m
setlocal autowrite
" comment/uncomment blocks of code (in vmode)
map  :s/^/#/gi<Enter>
map  :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>
" perlcritic selected lines (or entire file) with _p:
nnoremap <silent> _p :%!perlcritic -q<Enter>
vnoremap <silent> _p :!perlcritic -q<Enter>
endfunction
autocmd FileType perl call SetPerlIDE()
" map II :r ~/.vim/template.pod<CR>
set expandtab
set tabstop=4
set softtabstop=4
set shiftwidth=4
set autoindent
set number
set showmatch
set ruler
set backup
set lbr
set backupdir=~/.vim/backups
set directory=~/.vim/backups
set tags=~/.vim/tags
set backupskip=/tmp/*,/private/tmp/*"
set title
set titlestring=vim:\ %F
" we get colors, we get lots and lots of colors
syntax on
set bg=dark
colors oceanblack
" omnicompletion
filetype plugin on
set ofu=syntaxcomplete#Complete
source ~/.vim/plugin/supertab.vim
" macvim options
if has("gui_running")
set gfn=Menlo:h12
set guioptions-=r
set guioptions-=L
set guioptions-=T
set transparency=5
macm Window.Select\ Previous\ Tab key=<D-S-Left>
macm Window.Select\ Next\ Tab key=<D-S-Right>
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment