X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=vimrc;h=e209796979a08a4f66f23a6a80a387538415d569;hb=1c420fe0d57fd9e8bfbe59ab3fccca48f2f9ae2b;hp=d950d074e5d7242253d4f0300d81084c5b72de85;hpb=4e3363c35b35433bb7135841cfe27e57c72ad6bd;p=config%2Fdotfiles.git diff --git a/vimrc b/vimrc index d950d07..e209796 100644 --- a/vimrc +++ b/vimrc @@ -448,6 +448,9 @@ if has('autocmd') autocmd InsertLeave * set nopaste endif +" Save changes when running :mak[e] before 'makeprg' is called. + autocmd QuickFixCmdPre * write + " AFTER/FTPLUGIN AUTO COMMANDS " Disable spell checking for files which don't need it. @@ -465,6 +468,8 @@ if has('autocmd') \ setlocal textwidth=72 " Use the same comment string as for Vim files in Vimperator files. autocmd FileType vimperator setlocal commentstring=\"%s +" Use tex compiler for (La)TeX files. + autocmd FileType tex compiler tex " FTDETECT AUTO COMMANDS @@ -484,3 +489,52 @@ if has('autocmd') augroup END endif + + +" CUSTOM FUNCTIONS + +if has('eval') + " New text-objects ii and ai to work on text with the same indentation. + " Thanks to + " http://vim.wikia.com/index.php?title=Indent_text_object&oldid=27126 + " (visited on 2011-11-19). + onoremap ai :call IndTxtObj(0) + onoremap ii :call IndTxtObj(1) + vnoremap ai :call IndTxtObj(0)gv + vnoremap ii :call IndTxtObj(1)gv + + function! IndTxtObj(inner) + let curline = line(".") + let lastline = line("$") + let i = indent(line(".")) - &shiftwidth * (v:count1 - 1) + let i = i < 0 ? 0 : i + if getline(".") !~ "^\\s*$" + let p = line(".") - 1 + let nextblank = getline(p) =~ "^\\s*$" + while p > 0 + \ && ((i == 0 && !nextblank) + \ || (i > 0 && ((indent(p) >= i + \ && !(nextblank && a:inner)) + \ || (nextblank && !a:inner)))) + - + let p = line(".") - 1 + let nextblank = getline(p) =~ "^\\s*$" + endwhile + normal! 0V + call cursor(curline, 0) + let p = line(".") + 1 + let nextblank = getline(p) =~ "^\\s*$" + while p <= lastline + \ && ((i == 0 && !nextblank) + \ || (i > 0 && ((indent(p) >= i + \ && !(nextblank && a:inner)) + \ || (nextblank && !a:inner)))) + + + let p = line(".") + 1 + let nextblank = getline(p) =~ "^\\s*$" + endwhile + normal! $ + endif + endfunction + +endif