Skip to content

Instantly share code, notes, and snippets.

@breezhang
Last active May 30, 2016 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save breezhang/7942162 to your computer and use it in GitHub Desktop.
Save breezhang/7942162 to your computer and use it in GitHub Desktop.
simple good vimrc for perl
"copy from http://publius-ovidius.livejournal.com/242806.html
set nocompatible
set bs=2
set expandtab
set ts=4
set shiftwidth=4
set textwidth=78
set nowrap
set ruler
set autowrite
set hlsearch
set hidden
set autoindent
set fenc=utf8
set incsearch
set showmatch
set smarttab
filetype plugin on
syntax on
colorscheme evening " so we can actually read the darned comments
nohl " start without highlighting, fer crissakes
noremap ,pt :%!perltidy -q<cr> " only work in 'normal' mode
noremap ,qq :%s/(\n\s\+\(qq\?\)\[/(\1[<cr>
noremap ,c :!perl -Ilib -c %<cr>
noremap ,ca :!cvs annotate % <bar> less <cr>
noremap ,cl :!cvs diff % <bar> wc -l <cr>
noremap ,d :!perl -Ilib -d %<cr>
noremap ,h :nohl<cr>
noremap ,j :ls<cr>:e#
noremap ,pd :!perldoc %<cr>
noremap ,r :!perl -Ilib %<cr>
noremap ,s :!subs %<cr>
noremap ,t :!runtests -lpv -It/lib -It/tests "%"<cr>
noremap ,tc0 :%s/^\v\s*sub\s+\w+[^:]*:.*Tests?\s*(\(\s*(no_plan\|\d+)\s*\))?\s*\{.*$/& ;return;<cr>
noremap ,tc1 :%s/^\v(\s*sub\s+\w+[^:]*:.*Test.*\{.*) ;return;/\1/<cr>
noremap ,tm ?^sub.*:.*Test<cr>w"zyeOBEGIN { $ENV{TEST_METHOD} = '<c-r>z' }<esc>:nohl<cr>&
vnoremap ,pt :!perltidy -q<cr> " only work in 'visual' mode
vnoremap ,qq :s/(\n\s\+\(qq\?\)\[/(\1[<cr>
" automatically source the .vimrc file if I change it
" the bang (!) forces it to overwrite this command rather than stack it
au! BufWritePost .vimrc source %
noremap ,v :source ~/.vimrc<cr>
noremap ,V :e ~/.vimrc<cr>
" make sure the backspace key works
if &term=="xterm"
" this is a "control-v backspace"
set t_kb=^?
fixdel
endif
" make tab autocomplete :) http://www.vim.org/tips/tip.php?tip_id=102
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
" the following ensures that I cannot commit a file until I've done a quick
" code review
noremap ,cd :call SourceReview()<cr> " cvs diff
noremap ,cc :call SourceCommit()<cr> " cvs commit
let g:last_tick = 0
function! SourceReview()
:!cvs diff % | less
let g:last_tick = b:changedtick
endfunction
function! SourceCommit()
if g:last_tick == b:changedtick
:!EDITOR=/home/cpoe/bin/vim/bin/vim cvs commit %
let g:last_tick = b:changedtick
else
echohl WarningMsg
echo "You cannot commit source code until you review it"
echohl None
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment