"" to be synced with http://darkpan.com/vimrc set nocompatible " use vim -- not vi -- defaults set ls=2 " always show status line " Tabs v spaces "set tabstop=2 "set shiftwidth=2 set tabstop=4 "set tabstop=8 "set softtabstop=4 set smarttab set shiftwidth=4 set expandtab set showmatch " show matching braces set nowrap " don't wrap lines set number " show line numbers set autoindent "set smartindent set cindent " maybe? " For http://www.vim.org/scripts/script.php?script_id=3361 set background=dark set backspace=indent,eol,start " unindent with backspace, allow backspace to previous line and from start of insert mode ":set statusline=%<%f\ \ \ \ [%1*%M%*%n%R%H]\ %(\ %{StatusLineIndexLine()}%)\%=[%{&ff}\ %{&fileencoding}]\ [type=%Y]\ [ASCII=%03.3b\ HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [len=%L]\ ":set statusline=%<%f\ \ \ \ [%1*%M%*%n%R%H]\ \%=[%{&ff}\ %{&fileencoding}]\ [type=%Y]\ [ASCII=%03.3b\ HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [len=%L]\ :set statusline=%<%f\ \ \ \ [%1*%M%*%n%R%H]\ \%=[%{&ff}\ %{&fileencoding}]\ [type=%Y]\ [POS=%04l,%04v][%p%%]\ [len=%L] " source $VIMRUNTIME/mswin.vim behave xterm " ttymouse=xterm for tmux, xterm2 for screen set ttymouse=xterm set mouse=n " normal mode only: move around with mouse, but can paste in insert mode " Remap Ctrl+Z to suspend vim map :stop set nocursorline "" Bottom stuff set scrolloff=3 " keep 3 lines when scrolling set showcmd " show incomplete commands set hlsearch " highlight searchs set incsearch " do incremental search set ruler " show with cursor position "set visualbell t_vb= " turn off the visual bell set title " title terminal set ttyfast " smoother changes "set ttyscroll=0 " turn off scrolling -- does *not* work with PuTTY? set ignorecase " ignore case when searching "set infercase " infer case when searching set modeline " modelines may set the doc mode " when using a change command, keep showing the text that will be changed "set cpoptions=$ "" Syntax and highlighting syntax on " Highlights before selecting color scheme :autocmd ColorScheme * highlight Todo ctermbg=red ctermfg=white ":autocmd ColorScheme * highlight Normal ctermbg=NONE ":autocmd ColorScheme * highlight Normal ctermbg=NONE :autocmd BufWinEnter * match Todo /TODO/ :autocmd BufWinEnter * match Todo /TODO:/ :autocmd BufWinEnter * match Todo /FIXME/ :autocmd BufWinEnter * match Todo /FIXME:/ :autocmd BufWinEnter * match Todo /XXX/ :autocmd BufWinEnter * match Todo /MARCO/ " was grey instead of 242 :highlight NoTabs ctermbg=242 :autocmd BufWinEnter :highlight NoTabs ctermbg=242 :autocmd BufWinEnter * match NoTabs /\t/ :autocmd ColorScheme * highlight NoTabs ctermbg=242 :highlight TabLineFill ctermfg=black :highlight TabLine ctermfg=grey :highlight TabLineSel ctermfg=cyan if has("gui_running") set guifont=-b&h-lucidatypewriter-medium-r-normal-*-*-120-*-*-m-*-iso10646-1 "set guifont=Monospace\ 10 " this font colorscheme zenburn else " terminal supports 256 colors: set t_Co=256 "let g:zenburn_force_dark_Background = 1 "let g:zenburn_high_Contrast=1 colorscheme zenburn "colorscheme desert256 "set background=dark "colorscheme elflord " the Elf preservation society "highlight Normal ctermbg=NONE "highlight Normal ctermbg=NONE endif ":highlight MatchParen ctermbg=grey ctermfg=red " a( () 123 ) test( 123 ) " show trailing whitespace :autocmd BufWinEnter * highlight ExtraWhitespace ctermbg=darkred guibg=lightgreen :autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\t/ if has("autocmd") filetype plugin indent on " Various for helpfiles au BufnewFile,BufRead *.t set filetype=perl au BufnewFile,BufRead *.p[lm] set filetype=perl au BufnewFile,BufRead *.tt set filetype=html au BufnewFile,BufRead *.tmpl set filetype=html au FileType helpfile set nonumber " no line numbers on help files au FileType helpfile nnoremap " enter jumps to subject au FileType helpfile nnoremap " backspace jumps back " Perl stuff au FileType t,pl,pm,cgi set syntax=perl au BufnewFile,BufRead *.c setlocal makeprg=gcc\ -Wall\ % "au FileType perl set makeprg=perl\ -c\ %\ $* "au FileType perl set autowrite "au FileType perl set makeprg=perl\ $VIMRUNTIME/tools/efm_perl.pl\ -c\ %\ $* "" These if you use efm_perl.pl "au FileType perl set makeprg=perl\ $VIMRUNTIME/tools/efm_perl.pl\ -c\ % "au FileType perl set errorformat=%f:%l:%m " may work with efm_perl.pl """ Commented as I use ,c for warnings::unused and Vi::QuickFix au FileType perl set cinkeys-=0# " remove forced outdending of perl comments "au FileType perl set equalprg=perltidy " use perltidy for == or = "au FileType perl set foldmethod=syntax au FileType dot set makeprg=dot\ -T$*\ \"%:p\"\ -o\ \"%:p:r.$*\" " XML folding let g:xml_syntax_folding=1 au FileType xml setlocal foldmethod=syntax " TT2 templates au BufNewFile,BufRead *.tt source ~/.vim/plugin/matchit.vim au BufNewFile,BufRead *.tt set filetype=tt2html endif "" Keymaps map :previous " F2: previous buffer map :next " F3: next buffer map ,v :sp ~/.vimrc " ,v: edit ~/.vimrc in a split map ,e :e ~/.vimrc " ,e: edit ~/.vimrc in current buffer map ,u :source ~/.vimrc " ,u: update vimrc "" Normal mode remap ; to : -> ;w to write nnoremap ; : "" Normal mode remap ;; to :w to save nnoremap ;; :w "" Insert mode remap jj to act as Esc inoremap jj " map to close the current buffer set =[14~ map :close map :close " NERDTree toggling map :NERDTreeToggle map :NERDTreeToggle map ,t :!prove -I. --color --verbose % 2<&1 map ,T :!prove -I. --color --verbose % 2<&1 \| less map ,h :set filetype=html map ,H :set filetype=tt2html " use ,cd to LCD to the currently edited file's path map ,cd :lcd %:p:h " faster J and K map 3L map 3H "" Sets how to auto-complete with CTRL+P " :set complete=key,key,key " . Current file " b Files in loaded buffers, not in a window " d Definitions in the current file and in files included by a #include directive " i Files included by the current file through the use of a #include directive " k The file defined by the "dictionary" option (discussed later in this chapter) " kfile The file named {file} " t The "tags" file. (The ] character can be used as well.) " u Unloaded buffers " w Files in other windows " In my case, .,b,k should suffice (still testing!) set complete=.,d,b " perl -cw buffer, using a temp file, into a new window function! PerlCW() let l:tmpfile1 = tempname() let l:tmpfile2 = tempname() execute "normal:w!" . l:tmpfile1 . "\" execute "normal:! perl -cw ".l:tmpfile1." \> ".l:tmpfile2." 2\>\&1 \" execute "normal:new\" execute "normal:edit " . l:tmpfile2 . "\" endfunction " 'perl -cw' current buffer into a new window "function! BufferPerlCW() " let l:tmpfile1 = tempname() " let l:tmpfile2 = tempname() " execute "normal:w!" . l:tmpfile1 . "\" " execute "normal:!perl -I. -cw " . l:tmpfile1 . " \> " . l:tmpfile2 . " 2\>\&1 \" " execute "normal:tabnew\" " execute "normal:edit " . l:tmpfile2 . "\" "endfunction " "map :call BufferPerlCW() "imap :call BufferPerlCW() "map :make "imap :make " toggle/untoggle spelling map :setlocal spell! spelllang=en " toggle/untoggle autocomplpop map :AcpLock imap :AcpLock map :AcpUnlock imap :AcpUnlock map :!./% imap :!./% " Relative / Absolute line numbering map ,n :set rnu map ,N :set number " Easy foldlevels map ,zo :set foldlevel=9999 map ,zc :set foldlevel=1 " Open explorer with F12 map :E imap :E " Tab in visual mode indents nmap I nmap ^i " comma space to stop highlighting nmap , :nohl " reselect visual block after in/dedent so we can in/dedent more vnoremap < >gv " show tabs as a « followed by spaces, extends as dots, eol as paragraph set list "set listchars=tab:«-,trail:▒,extends:·,eol:¶,nbsp:░ "set listchars=tab:▕▁,trail:▒,extends:·,eol:¶,nbsp:░ "set listchars=tab:┕┉,trail:◇,extends:·,eol:¶,nbsp:░ set listchars=tab:┕┉,trail:▒,extends:·,eol:¶,nbsp:░ " set/unset paste with F11 set pastetoggle= " Perl does include pod stuff in the code let perl_include_pod=1 " And complex stuff may be found in code like @{${"foo"}} let perl_extended_vars=1 " let perl_string_as_statement=1 " Folding perl code let perl_fold=1 "let perl_fold_blocks=1 "unlet perl_nofold_packages let perl_nofold_packages=1 set foldmethod=syntax set foldcolumn=3 set foldlevel=0 " Perl syntax-check + warn on unused vars on the quickfix function! PerlPolice(...) let l:list=system("perl -Mwarnings::unused -MVi::QuickFix -wc " . shellescape(expand('%')) . " 2>&1") silent echon l:list "redir END "let old_efm = &efm "set efm=%f "if exists(":cgetfile") " execute "silent! cgetfile errors.err" "else " execute "silent! cfile errors.err" "endif "let &efm = old_efm "Open the quickfix window below the current window "botright copen 'errors.err' cf "errors.err" "call delete(tmpfile) call delete("errors.err") endfunction nnoremap ,c :call PerlPolice() " use Vi::QuickFix "nnoremap ,c :!time perl -Mwarnings::unused -MVi::QuickFix -wc % " quickfix for Perl error formats set errorformat+=%m\ at\ %f\ line\ %l set errorformat+=%m\ at\ %f\ line\ %l\. " For the PerlPolice above "set errorformat+=%f:%l:%m " Deparse code nnoremap ,D :.!perl -MO=Deparse 2>/dev/null vnoremap ,D :!perl -MO=Deparse 2>/dev/null " Git diff current buffer function! MF_git_diff_current_buffer() " Display diff in a buffer let command = 'silent $read !git diff ' . shellescape(expand("%")) botright new resize 20 setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap filetype=diff execute command setlocal nomodifiable "execute 'wincmd k' endfunction nnoremap ,d :call MF_git_diff_current_buffer() " Git commit current buffer function! MF_git_commit_current_buffer() call inputsave() let message = input("Commit message: ") call inputrestore() let command = ":!git commit % -m \"" . message . "\"" "echo command execute command endfunction nnoremap ,C :call MF_git_commit_current_buffer() " Set foldmethod to marker nnoremap ,f :set foldmethod=marker " or syntax nnoremap ,F :set foldmethod=syntax " Tidy selected lines (or entire file) with _t: if ( match(hostname(), 'dev') >= 0 ) " refactor perl code in a sub vmap \pr :!perl $HOME/bin/prefactor-extract-sub XXX endif " uses /usr/local/etc/perltidyrc nnoremap \t :%!perltidy -q vnoremap \t :!perltidy -q """"" http://search.cpan.org/dist/Perl-Tags/lib/Perl/Tags.pm setlocal iskeyword+=: " make tags with :: in them useful "if ! exists("s:defined_functions") " function s:init_tags() " perl <new( max_level=>2 ); " # only go one level down by default "EOF " endfunction " " " let vim do the tempfile cleanup and protection " let s:tagsfile = tempname() " " function s:do_tags(filename) " perl <process(files => $filename, refresh=>1 ); " my $tagsfile=VIM::Eval('s:tagsfile'); " VIM::SetOption("tags+=$tagsfile"); " # of course, it may not even output, for example, if there's nothing new to process " $naive_tagger->output( outfile => $tagsfile ); "EOF " endfunction " " call s:init_tags() " only the first time " " let s:defined_functions = 1 "endif " "call s:do_tags(expand('%')) "augroup perltags " au! " autocmd BufRead,BufWritePost *.cgi,*.pm,*.pl call s:do_tags(expand('%')) "augroup END """""" http://search.cpan.org/dist/Perl-Tags/lib/Perl/Tags.pm "" update screen term "autocmd BufEnter * let &titlestring = hostname() . "[vim(" . expand("%:t") . ")]" "autocmd BufEnter * let &titlestring = "vim(" . expand("%:t") . ")" "set titlestring=%t%(\ %M%)%(\ (%{expand(\"%:p:h\")})%) set titlestring=vim\ %t\ %M if &term == "screen" set t_ts= set t_fs= endif if &term == "screen" || &term == "xterm" set title endif " enable autocomplpop for perlomni. -- done automatically!! let g:acp_behaviorPerlOmniLength=4 let g:acp_enableAtStartup=0 " Find file in current (Git repos) directory, to edit it. function! Find(...) let l:gitrevparse=system("git rev-parse 2>&1") if strlen(l:gitrevparse) let tmpfile = tempname() exe "redir! > " . tmpfile silent echon "" redir END echo "Find: FATAL: not in a git repos" return endif let path="." if a:0==2 let path=a:2 endif let l:list=system("git ls-files '*" . a:1 . "*'") let l:num=strlen(substitute(l:list, "[^\n]", "", "g")) if l:num < 1 echo "Find: WARNING: '*".a:1."*' not found" return endif let tmpfile = tempname() exe "redir! > " . tmpfile silent echon l:list redir END let old_efm = &efm set efm=%f if exists(":cgetfile") execute "silent! cgetfile " . tmpfile else execute "silent! cfile " . tmpfile endif let &efm = old_efm "Open the quickfix window below the current window botright copen call delete(tmpfile) endfunction command! -nargs=* Find :call Find() "map ,gs "zyw:exe "!git show ".@z."" "map ,gS "zyw:exe "!git show --stat ".@z."" map ,8 :setlocal ts=8 map ,4 :setlocal ts=4 " Time to use HJKL "map "map "map "map "imap "imap "imap "imap " do not move when pressing out of insert mode: "inoremap `^ "" does not DWIW when entering via append mode, but hey " man / perldoc lookup " include colon (chr 58) in cword " look for manual page first, perldoc -q last "set iskeyword=@,48-58,_,192-255 "noremap K :!man perldoc perldoc -f perldoc -q ":let g:easytags_cmd = '/home/scfontma/ctags' let g:syntastic_auto_loc_list=1 set switchbuf="usetab" " reuse open buffer or tab when jumping to compilation errors etc "" for screen.vba, set default session terminal handler to Tmux let g:ScreenImpl="Tmux" "" For vim 7.3, set undo directory to ~/.vim/UNDO "set undodir=~/.vim/UNDO "set undofile "" do not keep undo files for files in /tmp "au BufWritePre /tmp/* setlocal noundofile "au BufReadPost * call ReadUndo() "au BufWritePost * call WriteUndo() "function! ReadUndo() " if filereadable(expand('%:h'). '/.vim/UNDO/' . expand('%:t')) " rundo %:h/.vim/UNDO/%:t " endif "endfunc "function! WriteUndo() " let dirname = expand('%:h') . '/.vim/UNDO' " if !isdirectory(dirname) " call mkdir(dirname) " endif " wundo %:h/.vim/UNDO/%:t "endfunc " the cursor will never be on the last line on the screen but this amount " above it: set scrolloff=3 " THIS GOES LAST -- don't write backup files set nobackup set nowritebackup " save swap files in ~/vim/TEMP set directory=~/.vim/TEMP// "let g:indent_guides_auto_colors = 0 "autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd ctermbg=236 "autocmd VimEnter,Colorscheme * :hi IndentGuidesEven ctermbg=238 " for project.vim - http://www.vim.org/scripts/script.php?script_id=69 let g:proj_window_increment=30