Last active
December 18, 2015 03:17
-
-
Save chemzqm/5b8099dd68213d590064 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put it under
~/.vim/plugin
and change it to whatever you like