From 8fe0d01df90da385e6f078e412ea8156a579e8aa Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Sun, 13 Mar 2011 14:50:06 -0700 Subject: [PATCH] Indentation for vimrc, and CursorHold --- .vimrc | 1131 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 587 insertions(+), 544 deletions(-) diff --git a/.vimrc b/.vimrc index 008ea77..092e7e1 100644 --- a/.vimrc +++ b/.vimrc @@ -15,8 +15,8 @@ set fenc=utf-8 " change cursor colour depending upon mode if exists('&t_SI') - let &t_SI = "\]12;lightgoldenrod\x7" - let &t_EI = "\]12;green\x7" + let &t_SI = "\]12;lightgoldenrod\x7" + let &t_EI = "\]12;green\x7" endif "----------------------------------------------------------------------- @@ -32,7 +32,7 @@ set history=500 " Return to last line if has("autocmd") - autocmd BufReadPost * + autocmd BufReadPost * \ if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif endif @@ -69,7 +69,7 @@ set lazyredraw set noerrorbells set visualbell t_vb= if has("autocmd") - autocmd GUIEnter * set visualbell t_vb= + autocmd GUIEnter * set visualbell t_vb= endif " Try to show at least three lines and two columns of context when @@ -93,7 +93,7 @@ set winminheight=1 " Enable syntax highlighting if has("syntax") - syntax on + syntax on endif " enable virtual edit in vblock mode, and one past the end @@ -101,22 +101,22 @@ set virtualedit=block " Set our fonts if has("gui_kde") - set guifont=Terminus/12/-1/5/50/0/0/0/0/0 + set guifont=Terminus/12/-1/5/50/0/0/0/0/0 elseif has("gui_gtk") - set guifont=Terminus\ 12 + set guifont=Terminus\ 12 elseif has("gui_running") - set guifont=-xos4-terminus-medium-r-normal--12-140-72-72-c-80-iso8859-1 + set guifont=-xos4-terminus-medium-r-normal--12-140-72-72-c-80-iso8859-1 endif " Try to load a nice colourscheme if ! has("gui_running") - set t_Co=256 - colors inkpot + set t_Co=256 + colors inkpot else - colors ir_black - " Turn off the menubar so we don't get key accelerators with Meta. - " Don't include the toolbar - set guioptions=aegit + colors ir_black + " Turn off the menubar so we don't get key accelerators with Meta. + " Don't include the toolbar + set guioptions=aegit endif " set background=light gives a different style, feel free to choose between them. set background=dark @@ -144,9 +144,9 @@ inoremap # X# " Enable folds if has("folding") - set foldenable - set foldmethod=marker - "set foldlevelstart=99 + set foldenable + set foldmethod=marker + "set foldlevelstart=99 endif " Syntax when printing @@ -154,16 +154,16 @@ set popt+=syntax:y " Enable filetype settings if has("eval") - filetype on - filetype plugin on - filetype indent on + filetype on + filetype plugin on + filetype indent on endif " Enable modelines only on secure vim versions if (v:version >= 604) - set modeline + set modeline else - set nomodeline + set nomodeline endif " Nice statusbar @@ -172,27 +172,27 @@ set statusline= set statusline+=%2*%-3.3n%0*\ " buffer number set statusline+=%f\ " file name if has("eval") - let g:scm_cache = {} - fun! ScmInfo() - let l:key = getcwd() - if ! has_key(g:scm_cache, l:key) - if (isdirectory(getcwd() . "/.git")) - let g:scm_cache[l:key] = "[" . substitute(readfile(getcwd() . "/.git/HEAD", "", 1)[0], - \ "^.*/", "", "") . "] " - else - let g:scm_cache[l:key] = "" - endif - endif - return g:scm_cache[l:key] - endfun - set statusline+=%{ScmInfo()} " scm info + let g:scm_cache = {} + fun! ScmInfo() + let l:key = getcwd() + if ! has_key(g:scm_cache, l:key) + if (isdirectory(getcwd() . "/.git")) + let g:scm_cache[l:key] = "[" . substitute(readfile(getcwd() . "/.git/HEAD", "", 1)[0], + \ "^.*/", "", "") . "] " + else + let g:scm_cache[l:key] = "" + endif + endif + return g:scm_cache[l:key] + endfun + set statusline+=%{ScmInfo()} " scm info endif set statusline+=%h%1*%m%r%w%0* " flags set statusline+=\[%{strlen(&ft)?&ft:'none'}, " filetype set statusline+=%{&encoding}, " encoding set statusline+=%{&fileformat}] " file format if filereadable(expand("$VIM/vimfiles/plugin/vimbuddy.vim")) - set statusline+=\ %{VimBuddy()} " vim buddy + set statusline+=\ %{VimBuddy()} " vim buddy endif set statusline+=%= " right align set statusline+=%2*0x%-8B\ " current char @@ -223,39 +223,39 @@ set statusline+=%-14.(%l,%c%V%)\ %<%P " offset " Nice window title if has('title') && (has('gui_running') || &title) - set titlestring= - set titlestring+=%f\ " file name - set titlestring+=%h%m%r%w " flags - "set titlestring+=\ -\ %{v:progname} " program name - set titlestring+=\ -\ %{substitute(getcwd(),\ $HOME,\ '~',\ '')} " working directory + set titlestring= + set titlestring+=%f\ " file name + set titlestring+=%h%m%r%w " flags + "set titlestring+=\ -\ %{v:progname} " program name + set titlestring+=\ -\ %{substitute(getcwd(),\ $HOME,\ '~',\ '')} " working directory endif " Backups and undos across edits if v:version >= 702 - set backupdir=~/.vim/backups + set backupdir=~/.vim/backups endif " NB: :help usr_32.txt or undo-branches if v:version >= 703 - set undodir=~/.vim/backups - set undofile + set undodir=~/.vim/backups + set undofile endif " For :X encryption if v:version >= 703 - set cryptmethod=blowfish + set cryptmethod=blowfish endif " If possible, try to use a narrow number column. if v:version >= 700 - try - setlocal numberwidth=3 - catch - endtry + try + setlocal numberwidth=3 + catch + endtry endif " Include $HOME in cdpath if has("file_in_path") - let &cdpath=','.expand("$HOME").','.expand("$HOME").'/work' + let &cdpath=','.expand("$HOME").','.expand("$HOME").'/work' endif " Better include path @@ -264,17 +264,17 @@ let &inc.=' ["<]' " Show tabs and trailing whitespace visually if (&termencoding == "utf-8") || has("gui_running") - if v:version >= 700 - set list listchars=tab:»·,trail:·,extends:…,nbsp:‗ - else - set list listchars=tab:»·,trail:·,extends:… - endif + if v:version >= 700 + set list listchars=tab:»·,trail:·,extends:…,nbsp:‗ + else + set list listchars=tab:»·,trail:·,extends:… + endif else - if v:version >= 700 - set list listchars=tab:>-,trail:.,extends:>,nbsp:_ - else - set list listchars=tab:>-,trail:.,extends:> - endif + if v:version >= 700 + set list listchars=tab:>-,trail:.,extends:>,nbsp:_ + else + set list listchars=tab:>-,trail:.,extends:> + endif endif map :set noet:set sw=8:set ts=8 map :set list! listchars @@ -285,6 +285,46 @@ map :set list! listchars set fillchars=fold:- +"----------------------------------------------------------------------- +" Preview window for :help CursorHold-example after updatetime +"----------------------------------------------------------------------- +au! CursorHold *.[ch] nested call PreviewWord() +func PreviewWord() + if &previewwindow " don't do this in the preview window + return + endif + let w = expand("") " get the word under cursor + if w =~ '\a' " if the word contains a letter + + " Delete any existing highlight before showing another tag + silent! wincmd P " jump to preview window + if &previewwindow " if we really get there... + match none " delete existing highlight + wincmd p " back to old window + endif + + " Try displaying a matching tag for the word under the cursor + try + exe "ptag " . w + catch + return + endtry + + silent! wincmd P " jump to preview window + if &previewwindow " if we really get there... + if has("folding") + silent! .foldopen " don't want a closed fold + endif + call search("$", "b") " to end of previous line + let w = substitute(w, '\\', '\\\\', "") + call search('\<\V' . w . '\>') " position cursor on match + " Add a match highlight to the word at this position + hi previewWord term=bold ctermbg=green guibg=green + exe 'match previewWord "\%' . line(".") . 'l\%' . col(".") . 'c\k*"' + wincmd p " back to old window + endif + endif +endfun "----------------------------------------------------------------------- " completion "----------------------------------------------------------------------- @@ -305,224 +345,223 @@ set dictionary=/usr/share/dict/words "----------------------------------------------------------------------- if has("eval") - - " If we're in a wide window, enable line numbers. - fun! WindowWidth() - if winwidth(0) > 90 - setlocal foldcolumn=2 - setlocal number - else - setlocal nonumber - setlocal foldcolumn=0 - endif - endfun + " If we're in a wide window, enable line numbers. + fun! WindowWidth() + if winwidth(0) > 90 + setlocal foldcolumn=2 + setlocal number + else + setlocal nonumber + setlocal foldcolumn=0 + endif + endfun endif " content creation if has("autocmd") - augroup puppet - autocmd BufRead,BufNewFile *.pp - \ set tabstop=2 shiftwidth=2 softtabstop=2 - augroup END - augroup text - autocmd BufRead,BufNewFile *.txt - \ set nonumber tw=80 - augroup END - augroup helphelp - " For help files, move them to the top window and make - " behave like (jump to tag) - "autocmd FileType help :call WindowToTop() - autocmd FileType help nmap - augroup END - augroup interplangs - autocmd BufNewFile *.rb 0put ='# vim: set sw=2 sts=2 et tw=80 :' | - \ 0put ='#!/usr/bin/env ruby' | set sw=2 sts=2 et tw=80 | - \ norm G + augroup puppet + autocmd BufRead,BufNewFile *.pp + \ set tabstop=2 shiftwidth=2 softtabstop=2 + augroup END + augroup text + autocmd BufRead,BufNewFile *.txt + \ set nonumber tw=80 + augroup END + augroup helphelp + " For help files, move them to the top window and make + " behave like (jump to tag) + "autocmd FileType help :call WindowToTop() + autocmd FileType help nmap + augroup END + augroup interplangs + autocmd BufNewFile *.rb 0put ='# vim: set sw=2 sts=2 et tw=80 :' | + \ 0put ='#!/usr/bin/env ruby' | set sw=2 sts=2 et tw=80 | + \ norm G - autocmd BufNewFile,BufRead *.rb,*rhtml,*haml - \ set tabstop=2 shiftwidth=2 softtabstop=2 | - \ setf eruby + autocmd BufNewFile,BufRead *.rb,*rhtml,*haml + \ set tabstop=2 shiftwidth=2 softtabstop=2 | + \ setf eruby - autocmd BufNewFile,BufRead *.php - \ set ai - augroup END - augroup tex - autocmd BufNewFile *.tex - \ 0put ='% vim:set ft=tex spell:' - augroup END - augroup html - autocmd BufNewFile *.htm,*.html - \ 0put ='' | - \ $put ='' | - \ $put =' ' | - \ $put =' ' | - \ $put =' ' | - \ $put =' ' | - \ $put =' ' | - \ $put =' ' | - \ $put =' ' | - \ $put =' ' | - \ $put ='' | - \ $put ='' | - \ set sw=2 sts=2 et tw=80 | norm G - augroup END - augroup autotools - autocmd BufNewFile *.hh 0put ='/* vim: set sw=4 sts=4 et foldmethod=syntax : */' | - \ 1put ='' | call MakeIncludeGuards() | - \ 5put ='#include \"config.h\"' | - \ set sw=4 sts=4 et tw=80 | norm G + autocmd BufNewFile,BufRead *.php + \ set ai + augroup END + augroup tex + autocmd BufNewFile *.tex + \ 0put ='% vim:set ft=tex spell:' + augroup END + augroup html + autocmd BufNewFile *.htm,*.html + \ 0put ='' | + \ $put ='' | + \ $put =' ' | + \ $put =' ' | + \ $put =' ' | + \ $put =' ' | + \ $put =' ' | + \ $put =' ' | + \ $put =' ' | + \ $put =' ' | + \ $put ='' | + \ $put ='' | + \ set sw=2 sts=2 et tw=80 | norm G + augroup END + augroup autotools + autocmd BufNewFile *.hh 0put ='/* vim: set sw=4 sts=4 et foldmethod=syntax : */' | + \ 1put ='' | call MakeIncludeGuards() | + \ 5put ='#include \"config.h\"' | + \ set sw=4 sts=4 et tw=80 | norm G - autocmd BufNewFile *.c 0put ='/* vim: set sw=4 sts=4 et foldmethod=syntax : */' | - \ 1put ='' | 2put ='' | call setline(3, '#include "' . - \ substitute(expand("%:t"), ".c$", ".h", "") . '"') | - \ set sw=4 sts=4 et tw=80 | norm G + autocmd BufNewFile *.c 0put ='/* vim: set sw=4 sts=4 et foldmethod=syntax : */' | + \ 1put ='' | 2put ='' | call setline(3, '#include "' . + \ substitute(expand("%:t"), ".c$", ".h", "") . '"') | + \ set sw=4 sts=4 et tw=80 | norm G - autocmd BufNewFile *.cc 0put ='/* vim: set sw=4 sts=4 et foldmethod=syntax : */' | - \ 1put ='' | 2put ='' | call setline(3, '#include "' . - \ substitute(expand("%:t"), ".cc$", ".hh", "") . '"') | - \ set sw=4 sts=4 et tw=80 | norm G + autocmd BufNewFile *.cc 0put ='/* vim: set sw=4 sts=4 et foldmethod=syntax : */' | + \ 1put ='' | 2put ='' | call setline(3, '#include "' . + \ substitute(expand("%:t"), ".cc$", ".hh", "") . '"') | + \ set sw=4 sts=4 et tw=80 | norm G - autocmd BufNewFile configure.ac - \ 0put ='dnl vim: set sw=8 sts=8 noet :' | - \ $put ='' | - \ call setline(line('$'), 'AC_INIT([' . substitute(expand('%:p:h'), - \ '^.\{-}/\([^/]\+\)\(/trunk\)\?$', '\1', '') . '], [0.1], [h.haugen@gmail.com])') | - \ $put ='AC_PREREQ(2.63)' | - \ $put ='AC_CONFIG_SRCDIR([])' | - \ $put ='AC_CONFIG_AUX_DIR(config)' | - \ $put ='AM_INIT_AUTOMAKE([foreign -Wall -Werror 1.10])' | - \ $put ='' | - \ $put ='dnl check for required programs' | - \ $put ='AC_PROG_CC dnl CXX' | - \ $put ='AC_PROG_INSTALL' | - \ $put ='AC_PROG_LN_S' | - \ $put ='AC_PROG_RANLIB' | - \ $put ='AC_PROG_MAKE_SET' | - \ $put ='' | - \ $put ='dnl output' | - \ $put ='AC_CONFIG_HEADERS([config.h])' | - \ $put ='AC_CONFIG_FILES([' | - \ $put =' Makefile' | - \ $put =' src/Makefile' | - \ $put ='])' | - \ $put ='AC_OUTPUT' | - \ set sw=8 sts=8 noet | - \ norm ggjjjjf] + autocmd BufNewFile configure.ac + \ 0put ='dnl vim: set sw=8 sts=8 noet :' | + \ $put ='' | + \ call setline(line('$'), 'AC_INIT([' . substitute(expand('%:p:h'), + \ '^.\{-}/\([^/]\+\)\(/trunk\)\?$', '\1', '') . '], [0.1], [h.haugen@gmail.com])') | + \ $put ='AC_PREREQ(2.63)' | + \ $put ='AC_CONFIG_SRCDIR([])' | + \ $put ='AC_CONFIG_AUX_DIR(config)' | + \ $put ='AM_INIT_AUTOMAKE([foreign -Wall -Werror 1.10])' | + \ $put ='' | + \ $put ='dnl check for required programs' | + \ $put ='AC_PROG_CC dnl CXX' | + \ $put ='AC_PROG_INSTALL' | + \ $put ='AC_PROG_LN_S' | + \ $put ='AC_PROG_RANLIB' | + \ $put ='AC_PROG_MAKE_SET' | + \ $put ='' | + \ $put ='dnl output' | + \ $put ='AC_CONFIG_HEADERS([config.h])' | + \ $put ='AC_CONFIG_FILES([' | + \ $put =' Makefile' | + \ $put =' src/Makefile' | + \ $put ='])' | + \ $put ='AC_OUTPUT' | + \ set sw=8 sts=8 noet | + \ norm ggjjjjf] - autocmd BufNewFile autogen.bash - \ 0put ='#!/usr/bin/env bash' | - \ 1put ='# vim: set sw=4 sts=4 et tw=80 :' | - \ $put ='run() {' | - \ $put ='echo \">>> $@\"' | - \ $put =' if ! $@ ; then' | - \ $put =' echo \"oops!\" 1>&2' | - \ $put =' exit 127' | - \ $put =' fi' | - \ $put ='}' | - \ $put ='' | - \ $put ='get() {' | - \ $put =' type ${1}-${2} &>/dev/null && echo ${1}-${2} && return' | - \ $put =' type ${1}${2//.} &>/dev/null && echo ${1}${2//.} && return' | - \ $put =' type ${1} &>/dev/null && echo ${1} && return' | - \ $put =' echo \"Could not find ${1} ${2}\" 1>&2' | - \ $put =' exit 127' | - \ $put ='}' | - \ $put ='' | - \ $put ='run mkdir -p config' | - \ $put ='run $(get libtoolize 2.2 ) --copy --force --automake' | - \ $put ='rm -f config.cache' | - \ $put ='run $(get aclocal 1.10 )' | - \ $put ='run $(get autoheader 2.63 )' | - \ $put ='run $(get autoconf 2.63 )' | - \ $put ='run $(get automake 1.10 ) -a --copy' | - \ set sw=4 sts=4 et tw=80 | - \ norm gg=Ggg - autocmd BufWritePost autogen.bash !chmod 744 % + autocmd BufNewFile autogen.bash + \ 0put ='#!/usr/bin/env bash' | + \ 1put ='# vim: set sw=4 sts=4 et tw=80 :' | + \ $put ='run() {' | + \ $put ='echo \">>> $@\"' | + \ $put =' if ! $@ ; then' | + \ $put =' echo \"oops!\" 1>&2' | + \ $put =' exit 127' | + \ $put =' fi' | + \ $put ='}' | + \ $put ='' | + \ $put ='get() {' | + \ $put =' type ${1}-${2} &>/dev/null && echo ${1}-${2} && return' | + \ $put =' type ${1}${2//.} &>/dev/null && echo ${1}${2//.} && return' | + \ $put =' type ${1} &>/dev/null && echo ${1} && return' | + \ $put =' echo \"Could not find ${1} ${2}\" 1>&2' | + \ $put =' exit 127' | + \ $put ='}' | + \ $put ='' | + \ $put ='run mkdir -p config' | + \ $put ='run $(get libtoolize 2.2 ) --copy --force --automake' | + \ $put ='rm -f config.cache' | + \ $put ='run $(get aclocal 1.10 )' | + \ $put ='run $(get autoheader 2.63 )' | + \ $put ='run $(get autoconf 2.63 )' | + \ $put ='run $(get automake 1.10 ) -a --copy' | + \ set sw=4 sts=4 et tw=80 | + \ norm gg=Ggg + autocmd BufWritePost autogen.bash !chmod 744 % - autocmd BufNewFile Makefile.am - \ 0put ='CLEANFILES = *~' | - \ if (! filereadable(expand("%:p:h:h") . '/Makefile.am')) | - \ $put ='MAINTAINERCLEANFILES = Makefile.in configure config/* aclocal.m4 \' | - \ $put ='' | - \ call setline(line('$'), "\t\t\tconfig.h config.h.in") | - \ $put ='SUBDIRS = src' | - \ $put ='AUTOMAKE_OPTIONS = foreign dist-bzip2' | - \ $put ='EXTRA_DIST = autogen.bash' | - \ $put ='' | - \ $put ='maintainer-clean-local:' | - \ $put =' -rmdir config' | - \ else | - \ $put ='MAINTAINERCLEANFILES = Makefile.in' | - \ $put ='bin_PROGRAMS = ' . substitute(expand('%:p:h'),'^.\{-}/\([^/]\+\)\(/src\)\?$', '\1', '') | - \ $put = substitute(expand('%:p:h'), '^.\{-}/\([^/]\+\)\(/src\)\?$','\1', '') . '_SOURCES = main.c' | - \ endif + autocmd BufNewFile Makefile.am + \ 0put ='CLEANFILES = *~' | + \ if (! filereadable(expand("%:p:h:h") . '/Makefile.am')) | + \ $put ='MAINTAINERCLEANFILES = Makefile.in configure config/* aclocal.m4 \' | + \ $put ='' | + \ call setline(line('$'), "\t\t\tconfig.h config.h.in") | + \ $put ='SUBDIRS = src' | + \ $put ='AUTOMAKE_OPTIONS = foreign dist-bzip2' | + \ $put ='EXTRA_DIST = autogen.bash' | + \ $put ='' | + \ $put ='maintainer-clean-local:' | + \ $put =' -rmdir config' | + \ else | + \ $put ='MAINTAINERCLEANFILES = Makefile.in' | + \ $put ='bin_PROGRAMS = ' . substitute(expand('%:p:h'),'^.\{-}/\([^/]\+\)\(/src\)\?$', '\1', '') | + \ $put = substitute(expand('%:p:h'), '^.\{-}/\([^/]\+\)\(/src\)\?$','\1', '') . '_SOURCES = main.c' | + \ endif - augroup END - augroup making - try - " if we have a vim which supports QuickFixCmdPost (vim7), - " give us an error window after running make, grep etc, but - " only if results are available. - autocmd QuickFixCmdPost * botright cwindow 5 + augroup END + augroup making + try + " if we have a vim which supports QuickFixCmdPost (vim7), + " give us an error window after running make, grep etc, but + " only if results are available. + autocmd QuickFixCmdPost * botright cwindow 5 - autocmd QuickFixCmdPre make - \ let g:make_start_time=localtime() + autocmd QuickFixCmdPre make + \ let g:make_start_time=localtime() - let g:paludis_configure_command = "! ./configure --prefix=/usr --sysconfdir=/etc" . - \ " --localstatedir=/var/lib --enable-qa " . - \ " --enable-ruby --enable-python --enable-vim --enable-bash-completion" . - \ " --enable-zsh-completion --with-repositories=all --with-clients=all --with-environments=all" . - \ " --enable-visibility --enable-gnu-ldconfig --enable-htmltidy" . - \ " --enable-ruby-doc --enable-python-doc --enable-xml" + let g:paludis_configure_command = "! ./configure --prefix=/usr --sysconfdir=/etc" . + \ " --localstatedir=/var/lib --enable-qa " . + \ " --enable-ruby --enable-python --enable-vim --enable-bash-completion" . + \ " --enable-zsh-completion --with-repositories=all --with-clients=all --with-environments=all" . + \ " --enable-visibility --enable-gnu-ldconfig --enable-htmltidy" . + \ " --enable-ruby-doc --enable-python-doc --enable-xml" - " Similarly, try to automatically run ./configure and / or - " autogen if necessary. - autocmd QuickFixCmdPre make - \ if ! filereadable('Makefile') | - \ if ! filereadable("configure") | - \ if filereadable("autogen.bash") | - \ exec "! ./autogen.bash" | - \ elseif filereadable("quagify.sh") | - \ exec "! ./quagify.sh" | - \ endif | - \ endif | - \ if filereadable("configure") | - \ if (isdirectory(getcwd() . "/paludis/util")) | - \ exec g:paludis_configure_command | - \ elseif (match(getcwd(), "libwrapiter") >= 0) | - \ exec "! ./configure --prefix=/usr --sysconfdir=/etc" | - \ else | - \ exec "! ./configure" | - \ endif | - \ endif | - \ endif + " Similarly, try to automatically run ./configure and / or + " autogen if necessary. + autocmd QuickFixCmdPre make + \ if ! filereadable('Makefile') | + \ if ! filereadable("configure") | + \ if filereadable("autogen.bash") | + \ exec "! ./autogen.bash" | + \ elseif filereadable("quagify.sh") | + \ exec "! ./quagify.sh" | + \ endif | + \ endif | + \ if filereadable("configure") | + \ if (isdirectory(getcwd() . "/paludis/util")) | + \ exec g:paludis_configure_command | + \ elseif (match(getcwd(), "libwrapiter") >= 0) | + \ exec "! ./configure --prefix=/usr --sysconfdir=/etc" | + \ else | + \ exec "! ./configure" | + \ endif | + \ endif | + \ endif - autocmd QuickFixCmdPost make - \ let g:make_total_time=localtime() - g:make_start_time | - \ echo printf("Time taken: %dm%2.2ds", g:make_total_time / 60, - \ g:make_total_time % 60) + autocmd QuickFixCmdPost make + \ let g:make_total_time=localtime() - g:make_start_time | + \ echo printf("Time taken: %dm%2.2ds", g:make_total_time / 60, + \ g:make_total_time % 60) - autocmd QuickFixCmdPre * - \ let g:old_titlestring=&titlestring | - \ let &titlestring="[ " . expand("") . " ] " . &titlestring | - \ redraw + autocmd QuickFixCmdPre * + \ let g:old_titlestring=&titlestring | + \ let &titlestring="[ " . expand("") . " ] " . &titlestring | + \ redraw - autocmd QuickFixCmdPost * - \ let &titlestring=g:old_titlestring + autocmd QuickFixCmdPost * + \ let &titlestring=g:old_titlestring - if hostname() == "snowmobile" - autocmd QuickFixCmdPre make - \ let g:active_line=getpid() . " vim:" . substitute(getcwd(), "^.*/", "", "") | - \ exec "silent !echo '" . g:active_line . "' >> ~/.config/awesome/active" + if hostname() == "snowmobile" + autocmd QuickFixCmdPre make + \ let g:active_line=getpid() . " vim:" . substitute(getcwd(), "^.*/", "", "") | + \ exec "silent !echo '" . g:active_line . "' >> ~/.config/awesome/active" - autocmd QuickFixCmdPost make - \ exec "silent !sed -i -e '/^" . getpid() . " /d' ~/.config/awesome/active" - endif + autocmd QuickFixCmdPost make + \ exec "silent !sed -i -e '/^" . getpid() . " /d' ~/.config/awesome/active" + endif - catch - endtry - augroup END + catch + endtry + augroup END endif "----------------------------------------------------------------------- @@ -553,8 +592,8 @@ nmap sp vi[:sort " Delete a buffer but keep layout if has("eval") - command! Kwbd enew|bw # - nmap ! :Kwbd + command! Kwbd enew|bw # + nmap ! :Kwbd endif " quickfix things @@ -606,8 +645,9 @@ nmap :exec "make -C " . expand("%:p:h") " Insert a single char noremap i ir -" Split the line +" Split the line into a (n)ew line or an (o)pen line nmap n \i +nmap o \ik$ " Pull the following line to the cursor position noremap J :s/\%#\(.*\)\n\(.*\)/\2\1 @@ -632,18 +672,18 @@ noremap gp gqap noremap clr :s/^.*$//:nohls " Delete blank lines -"noremap dbl :g/^$/d:nohls +noremap dbl :g/^$/d:nohls " Enclose each selected line with markers noremap enc :execute - \ substitute(":'<,'>s/^.*/#&#/ \| :nohls", "#", input(">"), "g") + \ substitute(":'<,'>s/^.*/#&#/ \| :nohls", "#", input(">"), "g") " Edit something in the current directory noremap ed :e =expand("%:p:h")/ " Enable fancy % matching if has("eval") - runtime! macros/matchit.vim + runtime! macros/matchit.vim endif " q: sucks @@ -651,184 +691,184 @@ nmap q: :q " set up some more useful digraphs if has("digraphs") - digraph ., 8230 " ellipsis (…) + digraph ., 8230 " ellipsis (…) endif if has("eval") - " Work out include guard text - fun! IncludeGuardText() - let l:p = substitute(substitute(getcwd(), "/trunk", "", ""), '^.*/', "", "") - let l:t = substitute(expand("%"), "[./]", "_", "g") - return substitute(toupper(l:p . "_GUARD_" . l:t), "-", "_", "g") - endfun + " Work out include guard text + fun! IncludeGuardText() + let l:p = substitute(substitute(getcwd(), "/trunk", "", ""), '^.*/', "", "") + let l:t = substitute(expand("%"), "[./]", "_", "g") + return substitute(toupper(l:p . "_GUARD_" . l:t), "-", "_", "g") + endfun - " Make include guards - fun! MakeIncludeGuards() - norm gg - /^$/ - norm 2O - call setline(line("."), "#ifndef " . IncludeGuardText()) - norm o - call setline(line("."), "#define " . IncludeGuardText() . " 1") - norm G - norm o - call setline(line("."), "#endif") - endfun - noremap ig :call MakeIncludeGuards() + " Make include guards + fun! MakeIncludeGuards() + norm gg + /^$/ + norm 2O + call setline(line("."), "#ifndef " . IncludeGuardText()) + norm o + call setline(line("."), "#define " . IncludeGuardText() . " 1") + norm G + norm o + call setline(line("."), "#endif") + endfun + noremap ig :call MakeIncludeGuards() endif " javascript folding if has("eval") - function! JavaScriptFold() - setl foldmethod=syntax - setl foldlevelstart=1 - syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend + function! JavaScriptFold() + setl foldmethod=syntax + setl foldlevelstart=1 + syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend - function! FoldText() - return substitute(getline(v:foldstart), '{.*', '{...}', '') - endfunction - setl foldtext=FoldText() + function! FoldText() + return substitute(getline(v:foldstart), '{.*', '{...}', '') endfunction - au FileType javascript call JavaScriptFold() - au FileType javascript setl fen + setl foldtext=FoldText() + endfunction + au FileType javascript call JavaScriptFold() + au FileType javascript setl fen endif " fast buffer switching if v:version >= 700 && has("eval") - let g:switch_header_map = { - \ 'cc': 'hh', - \ 'hh': 'cc', - \ 'c': 'h', - \ 'h': 'c', - \ 'cpp': 'hpp', - \ 'hpp': 'cpp' } + let g:switch_header_map = { + \ 'cc': 'hh', + \ 'hh': 'cc', + \ 'c': 'h', + \ 'h': 'c', + \ 'cpp': 'hpp', + \ 'hpp': 'cpp' } - fun! SwitchTo(f, split) abort - if ! filereadable(a:f) - echoerr "File '" . a:f . "' does not exist" - else - if a:split - new - endif - if 0 != bufexists(a:f) - exec ':buffer ' . bufnr(a:f) - else - exec ':edit ' . a:f - endif - endif - endfun + fun! SwitchTo(f, split) abort + if ! filereadable(a:f) + echoerr "File '" . a:f . "' does not exist" + else + if a:split + new + endif + if 0 != bufexists(a:f) + exec ':buffer ' . bufnr(a:f) + else + exec ':edit ' . a:f + endif + endif + endfun - fun! SwitchHeader(split) abort - let filename = expand("%:p:r") - let suffix = expand("%:p:e") - if suffix == '' - echoerr "Cannot determine header file (no suffix)" - return - endif + fun! SwitchHeader(split) abort + let filename = expand("%:p:r") + let suffix = expand("%:p:e") + if suffix == '' + echoerr "Cannot determine header file (no suffix)" + return + endif - let new_suffix = g:switch_header_map[suffix] - if new_suffix == '' - echoerr "Don't know how to find the header (suffix is " . suffix . ")" - return - end + let new_suffix = g:switch_header_map[suffix] + if new_suffix == '' + echoerr "Don't know how to find the header (suffix is " . suffix . ")" + return + end - call SwitchTo(filename . '.' . new_suffix, a:split) - endfun + call SwitchTo(filename . '.' . new_suffix, a:split) + endfun - fun! SwitchTest(split) abort - let filename = expand("%:p:r") - let suffix = expand("%:p:e") - if -1 != match(filename, '_TEST$') - let new_filename = substitute(filename, '_TEST$', '.' . suffix, '') - else - let new_filename = filename . '_TEST.' . suffix - end - call SwitchTo(new_filename, a:split) - endfun + fun! SwitchTest(split) abort + let filename = expand("%:p:r") + let suffix = expand("%:p:e") + if -1 != match(filename, '_TEST$') + let new_filename = substitute(filename, '_TEST$', '.' . suffix, '') + else + let new_filename = filename . '_TEST.' . suffix + end + call SwitchTo(new_filename, a:split) + endfun - fun! SwitchMakefile(split) abort - let dirname = expand("%:p:h") - if filereadable(dirname . "/Makefile.am.m4") - call SwitchTo(dirname . "/Makefile.am.m4", a:split) - elseif filereadable(dirname . "/Makefile.am") - call SwitchTo(dirname . "/Makefile.am", a:split) - else - call SwitchTo(dirname . "/Makefile", a:split) - endif - endfun + fun! SwitchMakefile(split) abort + let dirname = expand("%:p:h") + if filereadable(dirname . "/Makefile.am.m4") + call SwitchTo(dirname . "/Makefile.am.m4", a:split) + elseif filereadable(dirname . "/Makefile.am") + call SwitchTo(dirname . "/Makefile.am", a:split) + else + call SwitchTo(dirname . "/Makefile", a:split) + endif + endfun - noremap sh :call SwitchHeader(0) - noremap st :call SwitchTest(0) - noremap sk :call SwitchMakefile(0) - noremap ssh :call SwitchHeader(1) - noremap sst :call SwitchTest(1) - noremap ssk :call SwitchMakefile(1) + noremap sh :call SwitchHeader(0) + noremap st :call SwitchTest(0) + noremap sk :call SwitchMakefile(0) + noremap ssh :call SwitchHeader(1) + noremap sst :call SwitchTest(1) + noremap ssk :call SwitchMakefile(1) endif " super i_c-y / i_c-e if v:version >= 700 && has("eval") - fun! SuperYank(offset) - let l:cursor_pos = col(".") - let l:this_line = line(".") - let l:source_line = l:this_line + a:offset - let l:this_line_text = getline(l:this_line) - let l:source_line_text = getline(l:source_line) - let l:add_text = "" + fun! SuperYank(offset) + let l:cursor_pos = col(".") + let l:this_line = line(".") + let l:source_line = l:this_line + a:offset + let l:this_line_text = getline(l:this_line) + let l:source_line_text = getline(l:source_line) + let l:add_text = "" + let l:motion = "" . nr2char(getchar()) + if -1 != match(l:motion, '\d') + let l:count = 0 + while -1 != match(l:motion, '\d') + let l:count = l:count * 10 + l:motion let l:motion = "" . nr2char(getchar()) - if -1 != match(l:motion, '\d') - let l:count = 0 - while -1 != match(l:motion, '\d') - let l:count = l:count * 10 + l:motion - let l:motion = "" . nr2char(getchar()) - endwhile - else - let l:count = 1 - endif + endwhile + else + let l:count = 1 + endif - if l:motion == "$" - let l:add_text = strpart(l:source_line_text, l:cursor_pos - 1) - elseif l:motion == "w" - let l:add_text = strpart(l:source_line_text, l:cursor_pos - 1) - let l:add_text = substitute(l:add_text, - \ '^\(\s*\%(\S\+\s*\)\{,' . l:count . '}\)\?.*', '\1', '') - elseif l:motion == "f" || l:motion == "t" - let l:add_text = strpart(l:source_line_text, l:cursor_pos - 1) - let l:char = nr2char(getchar()) - let l:pos = matchend(l:add_text, - \ '^\%([^' . l:char . ']\{-}' . l:char . '\)\{' . l:count . '}') - if -1 != l:pos - let l:add_text = strpart(l:add_text, 0, l:motion == "f" ? l:pos : l:pos - 1) - else - let l:add_text = '' - endif - else - echo "Unknown motion: " . l:motion - endif + if l:motion == "$" + let l:add_text = strpart(l:source_line_text, l:cursor_pos - 1) + elseif l:motion == "w" + let l:add_text = strpart(l:source_line_text, l:cursor_pos - 1) + let l:add_text = substitute(l:add_text, + \ '^\(\s*\%(\S\+\s*\)\{,' . l:count . '}\)\?.*', '\1', '') + elseif l:motion == "f" || l:motion == "t" + let l:add_text = strpart(l:source_line_text, l:cursor_pos - 1) + let l:char = nr2char(getchar()) + let l:pos = matchend(l:add_text, + \ '^\%([^' . l:char . ']\{-}' . l:char . '\)\{' . l:count . '}') + if -1 != l:pos + let l:add_text = strpart(l:add_text, 0, l:motion == "f" ? l:pos : l:pos - 1) + else + let l:add_text = '' + endif + else + echo "Unknown motion: " . l:motion + endif - if l:add_text != "" - let l:new_text = strpart(l:this_line_text, 0, l:cursor_pos - 1) . - \ l:add_text . strpart(l:this_line_text, l:cursor_pos - 1) - call setline(l:this_line, l:new_text) - call cursor(l:this_line, l:cursor_pos + strlen(l:add_text)) - endif - endfun + if l:add_text != "" + let l:new_text = strpart(l:this_line_text, 0, l:cursor_pos - 1) . + \ l:add_text . strpart(l:this_line_text, l:cursor_pos - 1) + call setline(l:this_line, l:new_text) + call cursor(l:this_line, l:cursor_pos + strlen(l:add_text)) + endif + endfun - inoremap y :call SuperYank(-1) - inoremap e :call SuperYank(1) + inoremap y :call SuperYank(-1) + inoremap e :call SuperYank(1) endif " tab completion if has("eval") - function! CleverTab() - if strpart(getline('.'), 0, col('.') - 1) =~ '^\s*$' - return "\" - else - return "\" - endif - endfun - inoremap =CleverTab() - inoremap + function! CleverTab() + if strpart(getline('.'), 0, col('.') - 1) =~ '^\s*$' + return "\" + else + return "\" + endif + endfun + inoremap =CleverTab() + inoremap endif "----------------------------------------------------------------------- @@ -836,37 +876,37 @@ endif "----------------------------------------------------------------------- if has("eval") && has("autocmd") - fun! abbrev_cpp() - iabbrev raise throw - iabbrev jci const_iterator - iabbrev jcl class - iabbrev jco const - iabbrev jdb \bug - iabbrev jde \throws - iabbrev jdf /** \file/ - iabbrev jdg \ingroup - iabbrev jdn /** \namespace/ - iabbrev jdp \param - iabbrev jdt \test - iabbrev jdx /**/ - iabbrev jit iterator - iabbrev jns namespace - iabbrev jpr protected - iabbrev jpu public - iabbrev jpv private - iabbrev jsl std::list - iabbrev jsm std::map - iabbrev jss std::string - iabbrev jsv std::vector - iabbrev jty typedef - iabbrev jun using namespace - iabbrev jvi virtual - endfun + fun! abbrev_cpp() + iabbrev raise throw + iabbrev jci const_iterator + iabbrev jcl class + iabbrev jco const + iabbrev jdb \bug + iabbrev jde \throws + iabbrev jdf /** \file/ + iabbrev jdg \ingroup + iabbrev jdn /** \namespace/ + iabbrev jdp \param + iabbrev jdt \test + iabbrev jdx /**/ + iabbrev jit iterator + iabbrev jns namespace + iabbrev jpr protected + iabbrev jpu public + iabbrev jpv private + iabbrev jsl std::list + iabbrev jsm std::map + iabbrev jss std::string + iabbrev jsv std::vector + iabbrev jty typedef + iabbrev jun using namespace + iabbrev jvi virtual + endfun - augroup abbreviations - autocmd! - autocmd FileType cpp :call abbrev_cpp() - augroup END + augroup abbreviations + autocmd! + autocmd FileType cpp :call abbrev_cpp() + augroup END endif " NB: Need more of these for more than cpp @@ -875,17 +915,17 @@ endif "----------------------------------------------------------------------- if has("eval") && has("autocmd") - fun! check_pager_mode() - if exists("g:loaded_less") && g:loaded_less - " we're in vimpager / less.sh / man mode - set laststatus=0 - set ruler - set foldmethod=manual - set foldlevel=99 - set nolist - endif - endfun - autocmd VimEnter * :call check_pager_mode() + fun! check_pager_mode() + if exists("g:loaded_less") && g:loaded_less + " we're in vimpager / less.sh / man mode + set laststatus=0 + set ruler + set foldmethod=manual + set foldlevel=99 + set nolist + endif + endfun + autocmd VimEnter * :call check_pager_mode() endif "----------------------------------------------------------------------- @@ -893,106 +933,106 @@ endif "----------------------------------------------------------------------- if has("eval") - " Perl specific options - let perl_include_pod=1 - let perl_fold=1 - let perl_fold_blocks=1 + " Perl specific options + let perl_include_pod=1 + let perl_fold=1 + let perl_fold_blocks=1 - " Vim specific options - let g:vimsyntax_noerror=1 - let g:vimembedscript=0 + " Vim specific options + let g:vimsyntax_noerror=1 + let g:vimembedscript=0 - " c specific options - let g:c_gnu=1 - let g:c_no_curly_error=1 + " c specific options + let g:c_gnu=1 + let g:c_no_curly_error=1 - " eruby options - au Syntax * hi link erubyRubyDelim Directory + " eruby options + au Syntax * hi link erubyRubyDelim Directory - " ruby options - let ruby_operators=1 - let ruby_space_errors=1 + " ruby options + let ruby_operators=1 + let ruby_space_errors=1 - " php specific options - let php_sql_query=1 - let php_htmlInStrings=1 + " php specific options + let php_sql_query=1 + let php_htmlInStrings=1 - " Settings for taglist.vim - let Tlist_Use_Right_Window=1 - let Tlist_Auto_Open=0 - let Tlist_Enable_Fold_Column=0 - let Tlist_Compact_Format=1 - let Tlist_WinWidth=28 - let Tlist_Exit_OnlyWindow=1 - let Tlist_File_Fold_Auto_Close=1 - let Tlist_Inc_Winwidth=0 - "nnoremap :Tlist + " Settings for taglist.vim + let Tlist_Use_Right_Window=1 + let Tlist_Auto_Open=0 + let Tlist_Enable_Fold_Column=0 + let Tlist_Compact_Format=1 + let Tlist_WinWidth=28 + let Tlist_Exit_OnlyWindow=1 + let Tlist_File_Fold_Auto_Close=1 + let Tlist_Inc_Winwidth=0 + "nnoremap :Tlist - " Settings minibufexpl.vim - "let g:miniBufExplModSelTarget = 1 - "let g:miniBufExplWinFixHeight = 1 - "let g:miniBufExplWinMaxSize = 1 - " let g:miniBufExplForceSyntaxEnable = 1 + " Settings minibufexpl.vim + "let g:miniBufExplModSelTarget = 1 + "let g:miniBufExplWinFixHeight = 1 + "let g:miniBufExplWinMaxSize = 1 + " let g:miniBufExplForceSyntaxEnable = 1 - " Settings for showmarks.vim - if has("gui_running") - let g:showmarks_enable=1 + " Settings for showmarks.vim + if has("gui_running") + let g:showmarks_enable=1 + else + let g:showmarks_enable=0 + let loaded_showmarks=1 + endif + + let g:showmarks_include="abcdefghijklmnopqrstuvwxyz" + + if has("autocmd") + fun! FixShowmarksColours() + if has('gui') + hi ShowMarksHLl gui=bold guifg=#a0a0e0 guibg=#2e2e2e + hi ShowMarksHLu gui=none guifg=#a0a0e0 guibg=#2e2e2e + hi ShowMarksHLo gui=none guifg=#a0a0e0 guibg=#2e2e2e + hi ShowMarksHLm gui=none guifg=#a0a0e0 guibg=#2e2e2e + hi SignColumn gui=none guifg=#f0f0f8 guibg=#2e2e2e + endif + endfun + if v:version >= 700 + autocmd VimEnter,Syntax,ColorScheme * call FixShowmarksColours() else - let g:showmarks_enable=0 - let loaded_showmarks=1 + autocmd VimEnter,Syntax * call FixShowmarksColours() endif + endif - let g:showmarks_include="abcdefghijklmnopqrstuvwxyz" + " Settings for explorer.vim + let g:explHideFiles='^\.' - if has("autocmd") - fun! FixShowmarksColours() - if has('gui') - hi ShowMarksHLl gui=bold guifg=#a0a0e0 guibg=#2e2e2e - hi ShowMarksHLu gui=none guifg=#a0a0e0 guibg=#2e2e2e - hi ShowMarksHLo gui=none guifg=#a0a0e0 guibg=#2e2e2e - hi ShowMarksHLm gui=none guifg=#a0a0e0 guibg=#2e2e2e - hi SignColumn gui=none guifg=#f0f0f8 guibg=#2e2e2e - endif - endfun - if v:version >= 700 - autocmd VimEnter,Syntax,ColorScheme * call FixShowmarksColours() - else - autocmd VimEnter,Syntax * call FixShowmarksColours() - endif + " Settings for netrw + let g:netrw_list_hide='^\.,\~$' + + " Settings for :TOhtml + let html_number_lines=1 + let html_use_css=1 + let use_xhtml=1 + + " cscope settings + if has('cscope') && filereadable("/usr/bin/cscope") + set csto=0 + set cscopetag + set nocsverb + if filereadable("cscope.out") + cs add cscope.out endif + set csverb - " Settings for explorer.vim - let g:explHideFiles='^\.' - - " Settings for netrw - let g:netrw_list_hide='^\.,\~$' - - " Settings for :TOhtml - let html_number_lines=1 - let html_use_css=1 - let use_xhtml=1 - - " cscope settings - if has('cscope') && filereadable("/usr/bin/cscope") - set csto=0 - set cscopetag - set nocsverb - if filereadable("cscope.out") - cs add cscope.out - endif - set csverb - - let x = "sgctefd" - while x != "" - let y = strpart(x, 0, 1) | let x = strpart(x, 1) - exec "nmap " . y . " :cscope find " . y . - \ " =expand(\"\\")" - exec "nmap " . y . " :scscope find " . y . - \ " =expand(\"\\")" - endwhile - nmap i :cscope find i ^=expand("") - nmap i :scscope find i ^=expand("") - endif + let x = "sgctefd" + while x != "" + let y = strpart(x, 0, 1) | let x = strpart(x, 1) + exec "nmap " . y . " :cscope find " . y . + \ " =expand(\"\\")" + exec "nmap " . y . " :scscope find " . y . + \ " =expand(\"\\")" + endwhile + nmap i :cscope find i ^=expand("") + nmap i :scscope find i ^=expand("") + endif endif "----------------------------------------------------------------------- @@ -1033,9 +1073,9 @@ map map map :vsplit ~/.vim/ref_full.vim map :11vsplit ~/.vim/ref.vim -map :Sexplore /home/hunner/ +map :Sexplore $HOME map :2split ~/.vim/fun_ref.vim -map :set nu +map :set rnu! map :set nu! map ggVGg? map :set encoding=utf-8 | :set fenc=utf-8 @@ -1048,15 +1088,18 @@ map :set encoding=iso8859-15 | :set fenc=iso8859-15 nnoremap :noh map !!date map :TC -nmap :X :x -nmap :W :w -nmap :Q :q -nmap :B :b +nnoremap :X :x +nnoremap :W :w +nnoremap :Q :q +nnoremap :B :b noremap rg :color relaxedgreen noremap ip :color inkpot noremap ir :color ir_black -map t :FufFile -map d :FufDir +map f :FufFile +map b :FufBuffer +map c :FufDir +map w :bdelete +map :FufHelp noremap :syntax sync fromstart inoremap :syntax sync fromstart syntax sync minlines=200 @@ -1095,4 +1138,4 @@ endif " imap /me ACTION "----------------------------------------------------------------------- -" vim: set shiftwidth=4 softtabstop=4 expandtab tw=72 : +" vim: set shiftwidth=2 softtabstop=2 expandtab tw=72 :