"Damian Conway vimrc "=====[ Indenting support ]================== set wrapmargin=78 set autoindent "Retain indentation on next line set smartindent "Turn on autoindenting of blocks "But not magic outdenting of comments... inoremap # X# " Indent/outdent current block... "map %% $>i}`` "map $$ $ nnoremap v " Make BS/DEL work as expected vmap x "Square up visual selections set virtualedit=block "=====[ Toggle syntax highlighting ]============================== "nmap ;y : if exists("syntax_on") "\ syntax off "\else "\ syntax enable "\ endif "=====[ Insert POD markup and continue ]============================== " CTRL-C in insert mode inserts C<> and repositions cursor intelligently... inoremap C<>:silent call SetEscapesToSkip('1l') " ,c in normal mode wraps the current word in C<>... nmap ,c diWiC<-> " CTRL-E in insert mode inserts I<> and repositions cursor intelligently... inoremap I<>:silent call SetEscapesToSkip('1l') " ,i or ,e in normal mode wraps the current word in I<>... nmap ,i diWiI<-> nmap ,e diWiI<-> " Functions to make ESC or TAB after an insertion jump to after the insertion... function! SetEscapesToSkip (motion) execute 'inoremap :silent call ResetEscapes()' . a:motion . 'a ' execute 'inoremap :silent call ResetEscapes()' . a:motion . 'a ' endfunction function! SetEscapesToNextField (motion) execute 'inoremap :silent call SetEscapesToSkip("' . a:motion .'")/????4s' execute 'inoremap :silent call SetEscapesToSkip("' . a:motion .'")/????4s' endfunction function! ResetEscapes () iunmap call SetTabToCompletion() endfunction function! SetTabToCompletion () inoremap =WordTabAsCompletion("forward") endfunction "=====[ Miscellaneous features ]================================== set title "Show filename in titlebar of window set titleold= set nomore "Don't page long listings set autowrite "Save buffer automatically when changing files set autoread "Always reload buffer when external changes detected " What to save in .viminfo... set viminfo=h,'50,<10000,s1000,/1000,:100 set backspace=indent,eol,start "BS past autoindents, line boundaries, " and even the start of insertion set matchpairs+=<:>,«:» "Match angle brackets too set background=dark "When guessing, guess bg is dark set fileformats=unix,mac,dos "Handle Mac and DOS line-endings "but prefer Unix endings set wildmode=list:longest,full "Show list of completions " and complete as much as possible, " then iterate full completions set noshowmode "Suppress mode change messages set updatecount=10 "Save buffer every 10 chars typed set textwidth=78 "Wrap at column 78 set scrolloff=2 "Scroll when 2 lines from top/bottom set ruler "Show cursor location info on status line " Use space to jump down a page (like browsers do)... noremap " Keycodes and maps timeout in 3/10 sec... set timeout timeoutlen=300 ttimeoutlen=300 "=====[ Smarter completion ]================================== "Add file of std words for completion... set complete+=k~/.vim/std_completions "Adjust keyword characters for Perlish identifiers... set iskeyword+=: set iskeyword+=$ set iskeyword+=% set iskeyword+=@ set iskeyword-=, "=====[ Smarter searching ]================================== set incsearch "Lookahead as search pattern specified set ignorecase "Ignore case in all searches... set smartcase "...unless uppercase letters used set hlsearch "Highlight all search matches "Key mapping to switch off highlighting till next search... map H :nohlsearch "=====[ File navigation ]================================== " Edit a file... map e :n " Forward/back one file... map :next0 map :prev0 " Swap back to alternate file... map g :w:e # "=====[ Text formatting ]================================== " Format file with perltidy... map ;t 1G!Gperltidy " Format file with autoformat (capitalize to specify options)... "map F !Gformat -T4 - "map f !Gformat -T4 "=====[ Run Perl programs from within vim ]======================== " Execute Perl file... map W :!clear;perl -w % " Debug Perl file... map Q :!perl -d % " Run perldoc... map ?? :!pd set keywordprg=pd "=====[ Insert cut marks ]================================ map -- Ak6i-----cut----- "=====[ Manage tabs ]================================ " Convert file to different tabspacings function! NewTabSpacing (newtabsize) let was_expanded = &expandtab normal TT execute "set ts=" . a:newtabsize execute "set sw=" . a:newtabsize execute "map F !Gformat -T" . a:newtabsize . " -" execute "map f !Gformat -T" . a:newtabsize . "" if was_expanded normal TS endif endfunction map T! :call NewTabSpacing(1) map T@ :call NewTabSpacing(2) map T# :call NewTabSpacing(3) map T$ :call NewTabSpacing(4) map T% :call NewTabSpacing(5) map T^ :call NewTabSpacing(6) map T& :call NewTabSpacing(7) map T* :call NewTabSpacing(8) map T( :call NewTabSpacing(9) " Convert to/from spaces/tabs... map TS :set expandtab:%retab! map TT :set noexpandtab:%retab! "=====[ Spelling support ]================================== " Correct common mistypings in-the-fly... iab retrun return iab pritn print iab teh the iab liek like iab liekwise likewise iab Pelr Perl iab pelr perl iab ;t 't iab moer more iab previosu previous " Ring the bell every time "it's" is typed... imap it's it'sa "=====[ Insert mode shortcuts ]================================== " Insert shebang lines... iab hbc #! /bin/csh iab hbs #! /bin/sh iab hbp #! /usr/bin/perl -w " Insert common Perl code structures... iab udd use Data::Dumper 'Dumper';warn Dumper [];hi iab ubm use Benchmark qw( cmpthese );cmpthese -10, {};O iab usc use Smart::Comments;### iab pnl print \n";3hi iab uts use Test::Simple 'no_plan'; iab utm use Test::More 'no_plan'; iab dbs $DB::single = 1; iab rov Readonly my => ????;9h:silent call SetEscapesToNextField("2l")a "=====[ Highlight a common mistake ]================================== " Add new highlight combinations... highlight YELLOW_ON_BLACK ctermfg=yellow ctermbg=black highlight WHITE_ON_RED ctermfg=white ctermbg=red " Track "faux" references... function! BadRefs () match WHITE_ON_RED /_ref[ ]*[[{(]\|_ref[ ]*-[^>]/ endfunction call BadRefs() "=====[ Tab handling ]====================================== set tabstop=4 "Indentation levels every four columns set expandtab "Convert all tabs that are typed to spaces set shiftwidth=4 "Indent/outdent by four columns set shiftround "Indent/outdent to nearest tabstop function! WordTabAsCompletion(direction) let col = col('.') - 1 echo "" let prec = getline('.') if !col || col >=2 && prec[col-2 : col-1] =~ '[^:]:' || prec[col-1] !~ '\k' return "\" elseif "backward" == a:direction return "\" else return "\" endif endfunction inoremap =WordTabAsCompletion("forward") inoremap =WordTabAsCompletion("backward") "=====[ Grammar checking ]======================================== let g:check_grammar = 0 function! CheckGrammar () if g:check_grammar "match WHITE_ON_RED /_ref[ ]*[[{(]\|_ref[ ]*-[^>]/ call BadRefs() let g:check_grammar = 0 else match WHITE_ON_RED /\c\\|\\|\\|\\|\\|\\|\\|\\|\\|\/ let g:check_grammar = 1 endif echo "" endfunction " Toggle grammar checking... map ;g :call CheckGrammar()`` "=====[ Add or subtract comments ]=============================== function! ToggleComment () let currline = getline(".") if currline =~ '^#' s/^#// elseif currline =~ '\S' s/^/#/ endif endfunction map # :call ToggleComment()j0 "=====[ Highlight cursor column on request ]=================== highlight CursorColumn term=bold ctermfg=black ctermbg=green map ;c :set cursorcolumn! "=====[ Highlight spelling errors on request ]=================== set spelllang=en_au map ;s :setlocal invspell