" ~/.vimrc by Marius Gedminas " for VIM version 6 or later " " Caveat reader: this file is full of old cruft, although I've been trying " to clean it up bit by bit. " " I've tried to make it work with vim.tiny without errors, by sprinkling " conditionals all over the place. " " $Id: vimrc 500 2011-12-11 21:57:12Z mg $ " " " Options {{{1 " set nocompatible " be sane (default if you have a .vimrc) " Presentation {{{2 set laststatus=2 " always show a status line set cmdheight=2 " avoid 'Press ENTER to continue' set guioptions-=L " disable left scrollbar in GUI set guioptions-=m " disable GUI menu set showcmd " show partial commands in status line set ruler " show cursor position in status line set list " show tabs and spaces at end of line: set listchars=tab:>-,trail:.,extends:> if has("linebreak") let &sbr = nr2char(8618).' ' " Show ↪ at the beginning of wrapped lines endif if has("extra_search") set hlsearch " highlight search matches nohlsearch " but not initially endif if v:version >= 600 set listchars+=precedes:< endif if v:version >= 703 set colorcolumn=81 " highlight column 81 if exists('colorcolumn_hack') " just playing around; this is not actually a good idea (also, slow) for col in range(82, 200) let &colorcolumn = &colorcolumn . "," . col endfor endif endif " Fonts you might want to use: " " set guifont=DejaVu\ Sans\ Mono\ 10 " set guifont=Andale\ Mono\ 10 " Silence {{{2 set noerrorbells " don't beep! set visualbell " don't beep! set t_vb= " don't beep! (but also see below) " Interpreting file contents {{{2 set modelines=5 " debian disables this by default set fileencodings=ucs-bom,utf-8,windows-1252,iso-8859-13,latin1 " autodetect " Vim cannot distinguish between 8-bit encodings, so the last two " won't ever be considered. I keep them here for convenience: " :set fencs=, then delete the ones you don't want " Backup files {{{2 set backup " make backups set backupdir=~/tmp " but don't clutter $PWD with them if $USER == "root" " 'sudo vi' on certain machines cannot write to ~/tmp (NFS root-squash) set backupdir=/root/tmp endif if !isdirectory(&backupdir) " create the backup directory if it doesn't already exist exec "silent !mkdir -p " . &backupdir endif " Avoiding excessive I/O {{{2 set swapsync= " be more friendly to laptop mode (dangerous) " this could result in data loss, so beware! if v:version >= 700 set nofsync " be more friendly to laptop mode (dangerous) " this could result in data loss, so beware! endif " Behaviour {{{2 set wildmenu " nice tab-completion on the command line set wildmode=longest,full " nicer tab-completion on the command line set hidden " side effect: undo list is not lost on C-^ set browsedir=buffer " :browse e starts in %:h, not in $PWD set autoread " automatically reload files changed on disk set history=1000 " remember more lines of cmdline history set switchbuf=useopen " quickfix reuses open windows set iskeyword-=/ " Ctrl-W in command-line stops at / if has('mouse_xterm') set mouse=a " use mouse in xterms endif if v:version >= 600 set clipboard=unnamed " interoperate with the X clipboard set splitright " self-explanatory endif if v:version >= 700 set diffopt+=vertical " split diffs vertically set spelllang=en,lt " spell-check two languages at once endif " Movement {{{2 set incsearch " incremental searching set scrolloff=2 " always keep cursor 2 lines from screen edge set nostartofline " don't jump to start of line " Folding {{{2 if v:version >= 600 set foldmethod=marker " use folding by markers by default set foldlevelstart=9999 " initially open all folds endif " Editing {{{2 set backspace=indent,eol,start " sane backspacing set nowrap " do not wrap long lines set shiftwidth=4 " more-or-less sane indents set softtabstop=4 " make the key more useful set tabstop=8 " anything else is heresy set expandtab " sane default set noshiftround " do NOT enforce the indent set autoindent " automatic indent set nosmartindent " but no smart indent (ain't smart enough) set isfname-=\= " fix filename completion in VAR=/path " Editing code {{{2 set path+=** " let :find do recursive searches set tags-=./TAGS " ignore emacs tags to prevent duplicates set tags-=TAGS " ignore emacs tags to prevent duplicates set tags+=tags;$HOME " look for tags in parent dirs set suffixes+=.class " ignore Java class files set suffixes+=.pyc,.pyo " ignore compiled Python files set suffixes+=.~1~,.~2~ " ignore Bazaar droppings set wildignore+=*.pyc,*.pyo " same as 'suffixes', but for tab completion set wildignore+=*.o,*.d " same as 'suffixes', but for tab completion if v:version >= 700 set complete-=i " don't autocomplete from included files (too slow) " The following doesn't seem to do what I want it to do -- i.e. let me " complete common phrases with ^X^L. Should I look for a snippet plugin? set complete+=k~/.vim/python-snippets endif " Python tracebacks (unittest + doctest output) {{{2 set errorformat& set errorformat+= \File\ \"%f\"\\,\ line\ %l%.%#, \%C\ %.%#, \%-A\ \ File\ \"unittest%.py\"\\,\ line\ %.%#, \%-A\ \ File\ \"%f\"\\,\ line\ 0%.%#, \%A\ \ File\ \"%f\"\\,\ line\ %l%.%#, \%Z%[%^\ ]%\\@=%m " Shell scripts {{{2 if has("eval") let g:is_posix = 1 " /bin/sh is POSIX, not ancient Bourne shell endif " Persistent undo (vim 7.3+) {{{2 if has("persistent_undo") set undofile " enable persistent undo let &undodir=&backupdir . "/.vimundo" " but don't clutter $PWD if !isdirectory(&undodir) " create the undo directory if it doesn't already exist exec "silent !mkdir -p " . &undodir endif endif " Netrw explorer {{{2 if has("eval") let g:netrw_keepdir = 1 " does not work! let g:netrw_list_hide = '.*\.swp\($\|\t\),.*\.py[co]\($\|\t\)' let g:netrw_sort_sequence = '[\/]$,*,\.bak$,\.o$,\.h$,\.info$,\.swp$,\.obj$,\.py[co]$' let g:netrw_timefmt = '%Y-%m-%d %H:%M:%S' let g:netrw_use_noswf = 1 endif " " Plugins {{{1 " " Vundle {{{2 " git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle set rtp+=~/.vim/bundle/vundle/ runtime autoload/vundle.vim " apparently without this the exists() check fails if exists("*vundle#rc") filetype off call vundle#rc() " list all plugins you want to have like this: " Bundle "foo.vim" " Bundle "owner/project" for github-hosted stuff " Bundle "git://git.wincent.com/command-t.git" " install ones that are missing with :BundleInstall " install/upgrade them all with :BundleInstall! Bundle "gmarik/vundle" " Bundle "scrooloose/syntastic" <-- have it already in ~/.vim/plugin, " disabled because it was too slow " search for new ones with :BundleSearch keyword " bundles are kept in ~/.vim/bundle/ " read documentation at https://github.com/gmarik/vundle#readme endif " NB: " you would want to call vundle#rc() *before* filetype on " so bundles' ftdetect scripts are loaded " Filetype plugins {{{2 if v:version >= 600 filetype plugin on " load filetype plugins filetype indent on " load indent plugins endif " Syntastic {{{2 if has("eval") let g:syntastic_enable_signs = 1 " let g:syntastic_auto_loc_list = 1 " let g:syntastic_quiet_warnings = 1 " let g:syntastic_disabled_filetypes = ['ruby', 'php'] " On second thought, disable the plugin altogether: it's too slow let g:loaded_syntastic_plugin = 1 endif " Lusty explorer {{{2 if has("eval") let g:LustyExplorerSuppressRubyWarning = 1 endif " Command-t {{{2 if has("eval") let g:CommandTCursorEndMap = ['', ''] let g:CommandTCursorStartMap = ['', ''] endif "" Manual pages (:Man foo) {{{2 if v:version >= 600 runtime ftplugin/man.vim endif " Toggle between .c (.cc, .cpp) and .h {{{2 " ToggleHeader defined in $HOME/.vim/plugin/cpph.vim " Maybe these mappings should be moved into FT_C() ? map ,h :call ToggleHeader() map ,h imap " List all functions in a file {{{2 " functions defined in $HOME/.vim/plugin/funcs.vim " Maybe these mappings should be moved into FT_C() ? map ,l :call ListAllFunctions(1) map ,j :call JumpToFunction(0) " Python syntax highligting {{{2 " from http://hlabs.spb.ru/vim/python.vim if has("eval") let python_highlight_all = 1 let python_slow_sync = 1 endif " python_check_syntax.vim {{{2 if has("eval") " mnemonic: py[f]lakes (the default \cs is taken by VCSStatus) let g:pcs_hotkey = 'f' if has("user_commands") command! EnablePyflakesOnSave let g:pcs_check_when_saving = 1 command! DisablePyflakesOnSave exec 'py quickfix.maybeclose()' \| let g:pcs_check_when_saving = 0 endif endif " py-test-runner.vim {{{2 map ,t :CopyTestUnderCursor if has("user_commands") " :Co now expands to :CommandT, but I'm used to type it as a shortcut for " :CopyTestUnderCursor command! Co CopyTestUnderCursor " :E is now ambiguous, but I'm used to it command! E Explore endif " XML syntax folding {{{2 if has("eval") let xml_syntax_folding = 1 endif " XML tag complyetion {{{2 if has("eval") " because autocompleting when I type > is irritating half of the time let xml_tag_completion_map = "" endif " VCSCommand configuration {{{2 if has("eval") " I want 'edit' for VCSAnnotate, but 'split' for all others :( let VCSCommandEdit = 'split' let VCSCommandDeleteOnHide = 1 let VCSCommandCommitOnWrite = 0 endif " git ftplugin {{{2 if has("eval") let git_diff_spawn_mode = 1 endif " surround.vim {{{2 " make it not clobber 's' in visual mode vmap s Vsurround vmap S VSurround " NERD_tree.vim {{{2 if v:version >= 700 && has("eval") let g:NERDTreeIgnore= ['\.pyc$', '\~$'] let g:NERDTreeHijackNetrw = 0 endif " " Status line {{{1 " " I need to do this _after_ setting plugin options, since my statusline " relies on functions defined in some plugins, so I want to try to source " those plugins early to check if I need to define fallback functions, in " case those plugins are unavailable. " To emulate the standard status line with 'ruler' set, use this: " " set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P " " I've tweaked it a bit to show the buffer number on the left, and the total " number of lines on the right. Also, show the current Python function in the " status line, if the pythonhelper.vim plugin exists and can be loaded. runtime plugin/pythonhelper.vim if !exists("*TagInStatusLine") function TagInStatusLine() return '' endfunction endif runtime plugin/syntastic.vim if !exists("*SyntasticStatuslineFlag") function! SyntasticStatuslineFlag() return '' endfunction endif if !exists("*haslocaldir") function! HasLocalDir() return '' endfunction else function! HasLocalDir() if haslocaldir() return '[lcd]' endif return '' endfunction endif set statusline= " my status line contains: set statusline+=%n: " - buffer number, followed by a colon set statusline+=%<%f " - relative filename, truncated from the left set statusline+=\ " - a space set statusline+=%h " - [Help] if this is a help buffer set statusline+=%m " - [+] if modified, [-] if not modifiable set statusline+=%r " - [RO] if readonly set statusline+=%2*%{HasLocalDir()}%* " [lcd] if :lcd has been used set statusline+=%#warningmsg#%{SyntasticStatuslineFlag()}%* set statusline+=\ " - a space set statusline+=%1*%{TagInStatusLine()}%* " [current class/function] set statusline+=\ " - a space set statusline+=%= " - right-align the rest set statusline+=%-10.(%l,%c%V%) " - line,column[-virtual column] set statusline+=\ " - a space set statusline+=%4L " - total number of lines in buffer set statusline+=\ " - a space set statusline+=%P " - position in buffer as percentage " Other notes: " %1* -- switch to highlight group User1 " %{} -- embed the output of a vim function " %* -- switch to the normal highlighting " %= -- right-align the rest " %-10.(...%) -- left-align the group inside %(...%) " " Commands {{{1 " if has("user_commands") " how many occurrences of the current search pattern? {{{2 command! CountMatches %s///n " die, trailing whitespace! die! {{{2 command! NukeTrailingWhitespace %s/\s\+$// " diffoff sets wrap; don't wanna {{{2 command! Diffoff setlocal nodiff noscrollbind fdc=0 " See :help DiffOrig {{{2 command! DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis \ | wincmd p | diffthis " svncommand aliases that I'm used to {{{2 command! -nargs=* SVNAdd VCSAdd command! -nargs=* SVNBlame VCSAnnotate command! -nargs=? -bang SVNCommit VCSCommit command! -nargs=* SVNDiff VCSDiff command! -nargs=* SVNLog VCSLog command! -nargs=0 SVNRevert VCSRevert command! -nargs=* SVNStatus VCSStatus command! -nargs=0 SVNUpdate VCSUpdate command! -nargs=* SVNVimDiff VCSVimDiff command! -nargs=* BZRVimDiff VCSVimDiff " :CW {{{2 command! CW botright cw " Highlight group debugging {{{2 function! s:SynAttrs(id) return "" \ . (synIDattr(a:id, "font") != "" ? ' font:' . synIDattr(a:id, "font") : "") \ . (synIDattr(a:id, "fg") != "" ? ' fg:' . synIDattr(a:id, "fg") : "") \ . (synIDattr(a:id, "bg") != "" ? ' bg:' . synIDattr(a:id, "bg") : "") \ . (synIDattr(a:id, "sp") != "" ? ' sp:' . synIDattr(a:id, "sp") : "") \ . (synIDattr(a:id, "bold") ? " bold" : "") \ . (synIDattr(a:id, "italic") ? " italic" : "") \ . (synIDattr(a:id, "reverse") ? " reverse" : "") \ . (synIDattr(a:id, "standout") ? " standout" : "") \ . (synIDattr(a:id, "underline") ? " underline" : "") \ . (synIDattr(a:id, "undercurl") ? " undercurl" : "") endf function! s:ShowHighlightGroup() let hi = synID(line("."), col("."), 1) let trans = synID(line("."), col("."), 0) let lo = synIDtrans(hi) " In my experiments s:SynAttrs() always returns "" for hi and trans echo "hi<" . synIDattr(hi, "name") . '>' \ . s:SynAttrs(hi) \ . ' trans<' . synIDattr(trans, "name") . '>' \ . s:SynAttrs(trans) \ . ' lo<' . synIDattr(lo, "name") . '>' \ . s:SynAttrs(lo) endf function! s:ShowSyntaxStack() for id in synstack(line("."), col(".")) echo printf("%-20s %s", synIDattr(id, "name"), s:SynAttrs(synIDtrans(id))) endfor endf command! ShowHighlightGroup call s:ShowHighlightGroup() command! ShowSyntaxStack call s:ShowSyntaxStack() " :NoLCD {{{2 command! NoLCD exe 'cd '.getcwd() endif " has("user_commands") " " Keyboard macros {{{1 " " Digraphs {{{2 if has("digraphs") digraph -- 8212 " em dash digraph `` 8220 " left double quotation mark digraph '' 8221 " right double quotation mark digraph ,, 8222 " double low-9 quotation mark endif " Remember columns when jumping to marks {{{2 map ' ` " Undo in insert mode {{{2 " make it so that if I accidentally press ^W or ^U in insert mode, " then u will undo just the ^W/^U, and not the whole insert " This is documented in :help ins-special-special, a few pages down inoremap u inoremap u " */# search in visual mode (from www.vim.org) {{{2 " Atom \V sets following pattern to "very nomagic", i.e. only the backslash " has special meaning. " As a search pattern we insert an expression (= register) that " calls the 'escape()' function on the unnamed register content '@@', " and escapes the backslash and the character that still has a special " meaning in the search command (/|?, respectively). " This works well even with (no need to change ^I into \t), " but not with a linebreak, which must be changed from ^M to \n. " This is done with the substitute() function. " See http://vim.wikia.com/wiki/Search_for_visually_selected_text vnoremap * y/\V=substitute(escape(@@,"/\\"),"\n","\\\\n","ge") vnoremap # y?\V=substitute(escape(@@,"?\\"),"\n","\\\\n","ge") " S-Insert pastes {{{2 map! " .vimrc editing {{{2 set wildcharm= map ,e :e $HOME/.vim/vimrc map ,s :source $HOME/.vim/vimrc map ,PE :e $HOME/.vim/plugin/ map ,IE :e $HOME/.vim/indent/ map ,FE :e $HOME/.vim/ftplugin/ map ,XE :e $HOME/.vim/syntax/ " snipmate snippets! map ,SE ":e $HOME/.vim/snippets/".&ft."-mg.snippets\" map ,SS :call ReloadAllSnippets() " open a file in the same dir as the current one {{{2 map ,E ":e ".expand("%:h")."/" map ,,E ":e ".expand("%:h:h")."/" map ,,,E ":e ".expand("%:h:h:h")."/" map ,R ":e ".expand("%:r")."." " close just the deepest level of folds {{{2 map ,zm zMzRzm " Scrolling with Ctrl+Up/Down {{{2 map 1 map 1 imap imap " Scrolling with Ctrl+Shift+Up/Down {{{2 map 1 map 1 imap imap " Moving around with Shift+Up/Down {{{2 map { map } imap imap " Navigating around windows map map map map map map map map map! map! map! map! " Switching tabs with Alt-1,2,3 in gvim {{{2 map 1gt map 2gt map 3gt map 4gt map 5gt map 6gt map 7gt map 8gt map 9gt " Emacs style command line {{{2 cnoremap cnoremap cnoremap b cnoremap f " I wanted to delete to eol, but its primary function is too useful " and the implementation (with ) is too irritating ""cnoremap D " although here's a non-irritating implementation cmap estrpart(getcmdline(), 0, getcmdpos()-1) " Alt-Backspace deletes word backwards cnoremap " Do not lose "complete all" cnoremap " Windows style editing {{{2 imap dw imap db map "+p imap vmap "+y " ^Z = undo imap u " Function keys {{{2 " = help (default) "-" Disable F1 -- it gets in the way of Esc on my ThinkPad "-map "-imap " = save map :update imap " = turn off search highlighting map :nohlsearch imap " = next error/grep match "" depends on plugin/quickloclist.vim map :FirstOrNextInList imap " = previous error/grep match map :PrevInList imap " = current error/grep match map :CurInList imap " = switch files map imap " = toggle .c/.h (see above) or code/test (see below) " = jump to tag/filename+linenumber in the clipboard map :ClipboardTest " = highlight identifier under cursor " (some file-type dependent autocommands redefine it) map :let @/='\<'.expand('').'\>'set hls " = make map :make imap " = quit " (some file-type dependent autocommands redefine it) ""map :q ""imap " = toggle 'paste' set pastetoggle= " = show the Unicode name of the character under cursor map :UnicodeName " = show highlight group under cursor map :ShowHighlightGroup " = show syntax stack under cursor map :ShowSyntaxStack " " Keyboard workarounds {{{1 " " xterm keys {{{2 " keypad {{{3 map [5A map [5B map [5D map [5C map! [5A map! [5B map! [5D map! [5C map [2D map [2C map! [2D map! [2C map O6A map O6B map O6D map O6C map! O6A map! O6B map! O6D map! O6C map [5H map [5F map [5;5~ map [6;5~ map! [5H map! [5F map! [5;5~ map! [6;5~ " keypad in screen {{{3 map O5A map O5B map O5D map O5C map! O5A map! O5B map! O5D map! O5C map O2D map O2C map! O2D map! O2C map O5H map O5F map! O5H map! O5F " function keys {{{3 map O5P map O5Q map O5R map O5S map [15;5~ map [17;5~ map [18;5~ map [19;5~ map [20;5~ map [21;5~ map [23;5~ map [24;5~ map! O5P map! O5Q map! O5R map! O5S map! [15;5~ map! [17;5~ map! [18;5~ map! [19;5~ map! [20;5~ map! [21;5~ map! [23;5~ map! [24;5~ " rxvt keys {{{2 " keypad {{{3 map [a map [b map [d map [c map! [a map! [b map! [d map! [c map [2$ map [3$ map! [2$ map! [3$ " Other shifted keypad keys are used for scrollback and pasting map Oa map Ob map Od map Oc map! Oa map! Ob map! Od map! Oc map [2^ map [3^ map! [2^ map! [3^ map [3;5~ map! [3;5~ map [5^ map [6^ map [7^ map [8^ map! [5^ map! [6^ map! [7^ map! [8^ " numeric keypad {{{3 map Ox map Or map Ot map Ov map! Ox map! Or map! Ot map! Ov map Op map On map! Op map! On map Ow map Oq map Oy map Os map! Ow map! Oq map! Oy map! Os " Ignore KP_CENTER map Ou map! Ou " function keys {{{3 map [25~ map [26~ map [28~ map [29~ map [31~ map [32~ map [33~ map [34~ map [23$ map [24$ map! [25~ map! [26~ map! [28~ map! [29~ map! [31~ map! [32~ map! [33~ map! [34~ map! [23$ map! [24$ map [11^ map [12^ map [13^ map [14^ map [15^ map [17^ map [18^ map [19^ map [20^ map [21^ map [23^ map [24^ map! [11^ map! [12^ map! [13^ map! [14^ map! [15^ map! [17^ map! [18^ map! [19^ map! [20^ map! [21^ map! [23^ map! [24^ " gnome-terminal keys in Feisty {{{2 map O1;5A map O1;5B map O1;5D map O1;5C map! O1;5A map! O1;5B map! O1;5D map! O1;5C map O1;6A map O1;6B map O1;6D map O1;6C map! O1;6A map! O1;6B map! O1;6D map! O1;6C " gnome-terminal keys in Gutsy {{{2 map O1;2P map O1;2Q map O1;2R map O1;2S map [15;2~ map [17;2~ map [18;2~ map [19;2~ map [20;2~ " is not available map [23;2~ map [24;2~ map! O1;2P map! O1;2Q map! O1;2R map! O1;2S map! [15;2~ map! [17;2~ map! [18;2~ map! [19;2~ map! [20;2~ " is not available map! [23;2~ map! [24;2~ " is not available map O1;5Q map O1;5R map O1;5S map [15;5~ map [17;5~ map [18;5~ map [19;5~ map [20;5~ map [21;5~ map [23;5~ map [24;5~ " is not available map! O1;5Q map! O1;5R map! O1;5S map! [15;5~ map! [17;5~ map! [18;5~ map! [19;5~ map! [20;5~ map! [21;5~ map! [23;5~ map! [24;5~ " gnome-terminal keys in Hardy when ssh'ed into Dapper {{{2 " also, gnome-terminal keys in Intrepid {{{2 map [1;5A map [1;5B map [1;5D map [1;5C map! [1;5A map! [1;5B map! [1;5D map! [1;5C map [1;6A map [1;6B map [1;6D map [1;6C map! [1;6A map! [1;6B map! [1;6D map! [1;6C " " Autocommands {{{1 " if has("autocmd") " Kill visual bell! kill! {{{2 au GUIEnter * set t_vb= " Remember last position in a file {{{2 " see :help last-position-jump au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal g'\"" | endif " Autodetect filetype on first save {{{2 au BufWritePost * if &ft == "" | filetype detect | endif " Gettext files {{{2 " TeX/LaTeX {{{2 function! FT_TeX() if v:version >= 600 setlocal expandtab setlocal textwidth=78 else set expandtab set textwidth=78 endif " = start xdvi in background map :!xdvi %:r.dvi& imap " = process file with LaTeX map :!latex --src-specials % && killall -USR1 xdvi.bin 2>/dev/null imap " To get full benefits from --src-specials, put this in your ~/.Xresources: " XDvi.editor: gvim --remote +%l %f " Abbreviations ab \b \begin ab \e \end ab \begin{e} \begin{enumerate} ab \end{e} \end{enumerate} ab \begin{i} \begin{itemize} ab \end{i} \end{itemize} ab \begin{a} \begin{align*} ab \end{a} \end{align*} ab \begin{eq} \begin{equation} ab \end{eq} \end{equation} ab \i \item ab \d \documentclass[a4paper]{article} ab \D \Def ab \f \frac ab {\f {\frac ab (\f (\frac ab )\f )\frac ab -\f -\frac endf augroup TeX autocmd! autocmd FileType tex call FT_TeX() augroup END " Programming in C/C++ {{{2 function! FT_C() if v:version >= 600 setlocal formatoptions=croql setlocal cindent setlocal comments=sr:/*,mb:*,el:*/,:// setlocal shiftwidth=4 else set formatoptions=croql set cindent set comments=sr:/*,mb:*,el:*/,:// set shiftwidth=4 endif endf augroup C_prog autocmd! autocmd FileType c,cpp call FT_C() autocmd BufRead,BufNewFile /home/mg/src/brogue-*/**/*.[ch] setlocal ts=4 augroup END " Programming in Java {{{2 function! FT_Java() if v:version >= 600 setlocal formatoptions=croql setlocal cindent setlocal comments=sr:/*,mb:*,el:*/,:// setlocal shiftwidth=4 "setlocal efm=%A%f:%l:\ %m,%-Z%p^,%-C%.%# else set formatoptions=croql set cindent set comments=sr:/*,mb:*,el:*/,:// set shiftwidth=4 "set efm=%A%f:%l:\ %m,%-Z%p^,%-C%.%# endif endf augroup Java_prog autocmd! autocmd FileType java call FT_Java() augroup END " Programming in Perl {{{2 function! FT_Perl() if v:version >= 600 setlocal formatoptions=croql "" setlocal smartindent setlocal shiftwidth=4 else set formatoptions=croql "" set smartindent set shiftwidth=4 endif " = check syntax map :!perl -c % imap endf augroup Perl_prog autocmd! autocmd FileType perl call FT_Perl() augroup END " Programming in Python {{{2 function! PythonFoldLevel(lineno) let line = getline(a:lineno) " XXX very primitive at the moment if line == '' let line = getline(a:lineno + 1) if line =~ '^\(def\|class\)\>' return 0 elseif line =~ '^ \(def\|class\|#\)\>' return 1 else let lvl = foldlevel(a:lineno + 1) return lvl >= 0 ? lvl : '-1' endif elseif line =~ '^\(def\|class\)\>' return '>1' elseif line =~ '^ \(def\|class\)\>' return '>2' elseif line =~ '^[^ ]' " XXX used to be [^ #] return 0 elseif line =~ '^ [^ ]' " XXX used to be [^ #], why? what did I break by removing #? return 1 else let lvl = foldlevel(a:lineno - 1) return lvl >= 0 ? lvl : '=' endif endf function! FT_Python() if v:version >= 600 setlocal formatoptions=croql setlocal shiftwidth=4 setlocal softtabstop=4 setlocal expandtab setlocal indentkeys-=<:> setlocal indentkeys-=: " XXX I think python's syntax file makes autoindenting work, so my hack " with smartindent and cinwords is obsolete. ""setlocal cinwords=if,else,elif,while,for,try,except,finally,def,class ""setlocal smartindent " but it annoys me by not shifting # comment lines if &foldmethod != 'diff' setlocal foldmethod=expr endif setlocal foldexpr=PythonFoldLevel(v:lnum) " I don't want [I to parse import statements and look for modules setlocal include= " I work with Pylons projects ('/foo.mako' -> templates/foo.mako) more " often than I press gf on dotted names (foo.bar -> foo/bar.py) setlocal includeexpr=substitute(v:fname,'^/','','') " I sometimes use ## as a comment marker setlocal comments+=b:## syn sync minlines=100 match Error /\%>79v.\+/ map :ImportName map :ImportNameHere imap imap map :SwitchCodeAndTest map :setlocal makeprg=pyflakes\ %\|make else set formatoptions=croql "" set smartindent set shiftwidth=4 set expandtab endif abbr _pdb import pdb; pdb.set_trace() abbr _main if __name__ == "__main__": main() abbr _optparse parser = optparse.OptionParser("usage: %prog [options]" abbr improt import endf function! FT_Python_Ivija() map :wallsilent! !touch test-stamp python << END import sys, os pyflakes_path = os.path.expanduser('~/src/ivija/pyflakes-mg/') if pyflakes_path not in sys.path: sys.path.insert(0, pyflakes_path) modules_to_nuke = [m for m in sys.modules if m.startswith('pyflakes')] for m in modules_to_nuke: del sys.modules[m] END runtime plugin/python_check_syntax.vim " reload with new pyflakes version " XXX this means after editing one ivija file we're permanently on ivija's " pyflakes :/ endf augroup Python_prog autocmd! autocmd FileType python call FT_Python() autocmd BufRead,BufNewFile * if expand('%:p') =~ 'ivija' | call FT_Python_Ivija() | endif autocmd BufRead,BufNewFile * if expand('%:p') =~ 'schooltool' | let g:pyTestRunnerClipboardExtras='-pvc1' | let g:pyTestRunnerDirectoryFiltering = '' | let g:pyTestRunnerModuleFiltering = '' | endif autocmd BufRead,BufNewFile * if expand('%:p') =~ 'cipher' | let g:pyTestRunnerClipboardExtras='-c' | endif autocmd BufRead,BufNewFile /var/lib/buildbot/masters/*/*.cfg setlocal tags=/root/buildbot.tags augroup END augroup JS_prog autocmd! autocmd FileType javascript map :SwitchCodeAndTest augroup END function! FT_Mako() setf html setlocal includeexpr=substitute(v:fname,'^/','','') setlocal indentexpr= setlocal indentkeys-={,} endf augroup Mako_templ autocmd! autocmd BufRead,BufNewFile *.mako call FT_Mako() augroup END " Zope {{{2 function! FT_XML() setf xml if v:version >= 700 setlocal shiftwidth=2 softtabstop=2 expandtab fdm=syntax elseif v:version >= 600 setlocal shiftwidth=2 softtabstop=2 expandtab setlocal indentexpr= else set shiftwidth=2 softtabstop=2 expandtab endif endf function! FT_Maybe_ReST() if glob(expand("%:p:h") . "/*.py") != "" \ || glob(expand("%:p:h:h") . "/*.py") != "" setf rest setlocal shiftwidth=4 softtabstop=4 expandtab map :ImportName map :ImportNameHere map :SwitchCodeAndTest endif endf augroup Zope autocmd! autocmd BufRead,BufNewFile *.zcml call FT_XML() autocmd BufRead,BufNewFile *.pt call FT_XML() autocmd BufRead,BufNewFile *.tt setlocal et tw=44 wiw=44 autocmd BufRead,BufNewFile *.txt call FT_Maybe_ReST() augroup END " Diffs and patches {{{2 function! DiffFoldLevel(lineno) let line = getline(a:lineno) if line =~ '^Index:' return '>1' elseif line =~ '^RCS file: ' || line =~ '^retrieving revision ' let lvl = foldlevel(a:lineno - 1) return lvl >= 0 ? lvl : '=' elseif line =~ '^=== ' && getline(a:lineno - 1) =~ '^$\|^[-+ ]' return '>1' elseif line =~ '^===' let lvl = foldlevel(a:lineno - 1) return lvl >= 0 ? lvl : '=' elseif line =~ '^diff' return getline(a:lineno - 1) =~ '^retrieving revision ' ? '=' : '>1' elseif line =~ '^--- ' && getline(a:lineno - 1) !~ '^diff\|^===' return '>1' elseif line =~ '^@' return '>2' elseif line =~ '^[- +\\]' let lvl = foldlevel(a:lineno - 1) return lvl >= 0 ? lvl : '=' else return '0' endif endf function! FT_Diff() if v:version >= 600 setlocal foldmethod=expr setlocal foldexpr=DiffFoldLevel(v:lnum) else endif endf augroup Diffs autocmd! autocmd BufRead,BufNewFile *.patch setf diff autocmd FileType diff call FT_Diff() augroup END " /root/Changelog {{{2 function! FT_RootsChangelog() setlocal expandtab setlocal formatoptions=crql setlocal comments=b:#,fb:- endf augroup RootsChangelog autocmd! autocmd BufRead,BufNewFile /root/Changelog* call FT_RootsChangelog() augroup END " blog posts {{{2 function! FT_MyBlog() setlocal sts=2 sw=2 spell ft=html map :.!~/blog/blogify vmap :!~/blog/blogify imap map :!~/blog/preview.sh endf augroup MyBlog autocmd! autocmd BufRead,BufNewFile ~/blog/data/*.txt call FT_MyBlog() autocmd BufRead,BufNewFile ~/blog/blogify \ map :wall\|setlocal makeprg=%\ --test\|make augroup END " BookServ dev {{{2 function! FT_BookServ_Py() let g:pyTestRunner = 'bin/test' let g:pyTestRunnerTestFiltering = "-m" let g:pyTestRunnerDirectoryFiltering = "" let g:pyTestRunnerPackageFiltering = "" let g:pyTestRunnerModuleFiltering = "" let g:pyTestRunnerClipboardExtras = "" let g:pyTestRunnerFilenameFiltering = " " setlocal path^=src/bookserv/templates,src/bookserv/public setlocal includeexpr=substitute(v:fname,'^/','','') endf augroup BookServ autocmd! autocmd BufRead,BufNewFile ~/src/bookserv/*.py call FT_BookServ_Py() augroup END " " OpenEnd dev {{{2 function! FT_OpenEnd_Py() let g:pyTestRunner = 'bin/test' let g:pyTestRunnerTestFiltering = "-k" let g:pyTestRunnerClipboardExtras = "" let g:pyTestRunnerDirectoryFiltering = " " let g:pyTestRunnerPackageFiltering = "" let g:pyTestRunnerModuleFiltering = "" setlocal path^=cpanel/templates,cpanel/public setlocal includeexpr=substitute(v:fname,'^/','','') endf function! FT_OpenEnd_CPanel_Py() let g:pyTestRunner = 'bin/test-nojs' endf augroup OpenEnd autocmd! autocmd BufRead,BufNewFile ~/src/openend/*.py call FT_OpenEnd_Py() autocmd BufRead,BufNewFile ~/src/openend/cpanel/*.py call FT_OpenEnd_CPanel_Py() augroup END endif " has("autocmd") " " Colors {{{1 " if $COLORTERM == "gnome-terminal" set t_Co=256 " gnome-terminal supports 256 colors " note: doesn't work inside screen, which translates 256 colors into the " basic 16. " a better fix would be something like http://gist.github.com/636883 " added to .bashrc endif if has("gui_running") gui " see :help 'background' why I need this before set t_vb= " this must be set after :gui endif " I want gvims to look the same as vims in my gnome-terminal (which uses Tango " colours). Unfortunately I need to keep switching these manually whenever I " change the Gtk+ theme (between ones with white background and ones with dark " background). if !exists('colors_name') colorscheme whitetango "colorscheme darklooks endif if has("syntax") syntax enable endif " My colour overrides highlight NonText ctermfg=gray guifg=gray term=standout highlight SpecialKey ctermfg=gray guifg=gray term=standout highlight MatchParen gui=bold guibg=NONE guifg=lightblue cterm=bold ctermbg=NONE highlight SpellBad cterm=underline ctermfg=red ctermbg=NONE highlight SpellCap cterm=underline ctermfg=blue ctermbg=NONE if $TERM == "Eterm" highlight StatusLine ctermfg=white ctermbg=black cterm=bold highlight StatusLineNC ctermfg=white ctermbg=black cterm=NONE highlight VertSplit ctermfg=white ctermbg=black cterm=NONE endif " Get rid of italics (they look ugly) highlight htmlItalic gui=NONE guifg=orange highlight htmlUnderlineItalic gui=underline guifg=orange " Make error messages more readable highlight ErrorMsg guifg=red guibg=white " Python doctests -- I got used to one color, then upgraded the Python " syntax script and it changed it highlight link Test Special " 'statusline' contains %1* and %2* highlight User1 gui=NONE guifg=green guibg=black highlight User2 gui=NONE guifg=magenta guibg=black " for custom :match commands highlight Red guibg=red ctermbg=red highlight Green guibg=green ctermbg=green " " Toolbar buttons {{{1 " if !exists("did_install_mg_menus") && has("gui") let did_install_mg_menus = 1 amenu 1.200 ToolBar.-Sep700- : amenu 1.201 ToolBar.TrimSpaces :%s/\s\+$// tmenu ToolBar.TrimSpaces Remove trailing whitespace amenu 1.202 ToolBar.ToggleHdr tmenu ToolBar.ToggleHdr Switch between source and header (C/C++), or code and test (Python) endif