From: Samir Benmendil Date: Tue, 23 Aug 2016 08:12:41 +0000 (+0100) Subject: vim: add togglelist plugin X-Git-Url: https://git.rmz.io/dotfiles.git/commitdiff_plain/c680b2fc4a1f6553616d2c104611c6df2e3b7c21?ds=inline vim: add togglelist plugin --- diff --git a/vim/after/plugin/togglelist.vim b/vim/after/plugin/togglelist.vim new file mode 100644 index 0000000..01ba8de --- /dev/null +++ b/vim/after/plugin/togglelist.vim @@ -0,0 +1,67 @@ +" toggle unite, quickfix list and location list +if exists("g:loaded_toggle_list") + finish +endif + +let g:loaded_toggle_list = 1 + +function! s:GetBufferList() + redir =>buflist + silent! ls + redir END + return buflist +endfunction + +function! s:ToggleLocationList() + for bufnum in map(filter(split(s:GetBufferList(), '\n'), 'v:val =~# "Location List"'), 'str2nr(matchstr(v:val, "\\d\\+"))') + lclose + return + endfor + + let last = winnr('$') + + try + Errors + catch + try + lopen + catch /E776/ + endtry + endtry + if last == winnr('$') + echohl WarningMsg | echon 'No Location List' | echohl None + endif +endfunction + +function! s:ToggleQuickfixList() + for bufnum in map(filter(split(s:GetBufferList(), '\n'), 'v:val =~ "Quickfix List"'), 'str2nr(matchstr(v:val, "\\d\\+"))') + if bufwinnr(bufnum) != -1 + cclose + return + endif + endfor + let winnr = winnr() + copen 10 + if winnr() != winnr + wincmd p + endif +endfunction + + +function! s:ToggleUnite() + for i in range(1, winnr('$')) + let name = bufname(winbufnr(i)) + if match(name, '^\[unite\]') == 0 + UniteClose + return + endif + endfor + UniteResume +endfunction + +nmap [oq :copen +nmap ]oq :cclose +nmap coq :call ToggleLocationList() +nmap [ol :lopen +nmap ]ol :lclose +nmap col :call ToggleQuickfixList()