From 3e96b69d271a918b8f71dce65594860517c40118 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Thu, 18 Dec 2014 15:43:53 +0100 Subject: [autocmds] Groups all autocommands into augroups --- vimrc | 110 ++++++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 70 insertions(+), 40 deletions(-) diff --git a/vimrc b/vimrc index 6ce8fbc..b2c7393 100644 --- a/vimrc +++ b/vimrc @@ -57,14 +57,12 @@ nmap :set invet " folding set foldmethod=indent set foldignore= -autocmd BufRead *.[ch] setlocal foldmethod=syntax -autocmd BufRead /tmp/mutt-*[0-9] setlocal foldmethod=expr -autocmd BufRead /tmp/mutt-*[0-9] setlocal foldexpr=(strlen(substitute(matchstr(getline(v:lnum),\"^\ *[>\ ]*\"),\"\ *\",\"\",\"g\"))) -" Highlights columns 77-80 and 81+ -autocmd BufRead /tmp/mutt-*[0-9] let w:m1=matchadd('Search', '\%<81v.\%>77v', -1) -autocmd BufRead /tmp/mutt-*[0-9] let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1) - - +augroup Folding + au! + autocmd FileType c\|cpp setlocal foldmethod=syntax + autocmd FileType mail setlocal foldmethod=expr + autocmd FileType mail setlocal foldexpr=(strlen(substitute(matchstr(getline(v:lnum),\"^\ *[>\ ]*\"),\"\ *\",\"\",\"g\"))) +augroup END set foldminlines=0 set foldcolumn=5 @@ -94,7 +92,7 @@ nmap j :bn nmap k :bN nmap l :tabn -augroup skel +augroup Skeleton au! " read in skeleton files autocmd BufNewFile *.* silent! 0r ~/.vim/skel/%:e @@ -103,14 +101,17 @@ augroup skel autocmd BufNewFile * silent! %substitute#<=CURSOR=>##g augroup END -" When editing a file, always jump to the last known cursor position. -" Don't do it when the position is invalid or when inside an event handler -" (happens when dropping a file on gvim). -autocmd BufReadPost * - \ if line("'\"") > 0 && line("'\"") <= line("$") | - \ exe "normal g`\"" | - \ exe "normal zz" | - \ endif +augroup Load + au! + " When editing a file, always jump to the last known cursor position. + " Don't do it when the position is invalid or when inside an event handler + " (happens when dropping a file on gvim). + autocmd BufReadPost * + \ if line("'\"") > 0 && line("'\"") <= line("$") | + \ exe "normal g`\"" | + \ exe "normal zz" | + \ endif +augroup END function! CscopeSearch(csearch) @@ -162,9 +163,11 @@ function! LoadTags() endfunction call LoadTags() -" F*cking whitespaces -autocmd BufRead * highlight ExtraWhitespace ctermbg=red ctermfg=black guibg=red -autocmd BufRead * match ExtraWhitespace /\s\+$\| \+\ze\t\| \+\|\t\zs \+/ +augroup WhiteSpaces + " F*cking whitespaces + autocmd BufRead * highlight ExtraWhitespace ctermbg=red ctermfg=black guibg=red + autocmd BufRead * match ExtraWhitespace /\s\+$\| \+\ze\t\| \+/ +augroup END set list listchars=tab:│ ,precedes:‥,extends:‥,nbsp:␣ nmap :set invlist @@ -260,21 +263,30 @@ endfunction command! GitBlameCurrentLine :call GitBlameCurrentLine() map b :GitBlameCurrentLine -" n goto next empty reply-to paragraph -" m opens an empty reply-paragraph at this line -" d deletes everything until but the signature -" w reformats entire mail but the signature -" D deletes everything until but the previous reply-to § -autocmd BufRead /tmp/mutt-*[0-9a-f] map n /^> $ -autocmd BufRead /tmp/mutt-*[0-9a-f] map D ^d?^\([^>]\\|$\)?+O -autocmd BufRead /tmp/mutt-*[0-9a-f] map d ^d/^-- $O -autocmd BufRead /tmp/mutt-*[0-9a-f] map w ggv/^-- $:!par rTbgqRe 'B=.,?_A_a' 'Q=_s>\|' - -set spelllang=fr,en,de -autocmd BufRead /tmp/mutt-*[0-9a-f] setlocal spell -autocmd BufRead /tmp/mutt-*[0-9a-f] setlocal textwidth=74 -autocmd BufRead /tmp/mutt-*[0-9a-f] execute Erase_Sig_but_Your() -autocmd BufRead /tmp/mutt-*[0-9a-f] :normal ,n +augroup MailEditor + au! + + " Highlights columns 77-80 and 81+ + autocmd BufRead /tmp/mutt-*[0-9] let w:m1=matchadd('Search', '\%>77v,\+', -1) + autocmd BufRead /tmp/mutt-*[0-9] let w:m2=matchadd('ErrorMsg', '\%>81v,\+', -1) + + " n goto next empty reply-to paragraph + " m opens an empty reply-paragraph at this line + " d deletes everything until but the signature + " w reformats entire mail but the signature + " D deletes everything until but the previous reply-to § + autocmd FileType mail noremap n /^> $ + autocmd FileType mail noremap D ^d?^\([^>]\\|$\)?+O + autocmd FileType mail noremap d ^d/^-- $O + autocmd FileType mail noremap w ggv/^-- $:!par rTbgqRe 'B=.,?_A_a' 'Q=_s>\|' + + set spelllang=fr,en,de + autocmd FileType mail setlocal spell + autocmd FileType mail setlocal textwidth=74 + autocmd FileType mail execute Erase_Sig_but_Your() + + autocmd FileType mail :normal ,n +augroup END map zc z=1 @@ -285,13 +297,31 @@ function! SetLocalTabs(tabsize) setlocal smarttab setlocal expandtab endfunction -autocmd BufAdd *.py execute SetLocalTabs(4) -autocmd BufEnter * set cursorline -autocmd WinEnter * set cursorline -autocmd BufLeave * set nocursorline -autocmd WinLeave * set nocursorline +"" +"" DafUq ? +""-------- +"augroup Tabs +" au! +" autocmd FileType python execute SetLocalTabs(4) +"augroup END +" + +augroup CursorLine + au! + + " when switching between buffers + autocmd BufEnter * set cursorline + autocmd BufLeave * set nocursorline + " when switching between windows + autocmd WinEnter * set cursorline + autocmd WinLeave * set nocursorline + + " doesn’t seem to work on urxvt :( + autocmd FocusLost * set nocursorline + autocmd FocusGained * set cursorline +augroup END " footnotes inoremap ,, :call VimFootnotes() -- cgit v1.2.3