Skip to content

Instantly share code, notes, and snippets.

@chemzqm
Last active December 18, 2015 03:17
Show Gist options
  • Save chemzqm/5b8099dd68213d590064 to your computer and use it in GitHub Desktop.
Save chemzqm/5b8099dd68213d590064 to your computer and use it in GitHub Desktop.
" 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 <silent> <leader>u :call <SID>ToggleUnite()<cr>
nmap <silent> <leader>l :call <SID>ToggleLocationList()<CR>
nmap <silent> <leader>f :call <SID>ToggleQuickfixList()<CR>
@chemzqm
Copy link
Author

chemzqm commented Dec 18, 2015

Put it under ~/.vim/plugin and change it to whatever you like

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment