quickfix.vim (587B)
1 function! GetBufferList() 2 redir =>buflist 3 silent! ls! 4 redir END 5 return buflist 6 endfunction 7 8 function! ToggleList(bufname, pfx) 9 let buflist = GetBufferList() 10 for bufnum in map(filter(split(buflist, '\n'), 'v:val =~ "'.a:bufname.'"'), 'str2nr(matchstr(v:val, "\\d\\+"))') 11 if bufwinnr(bufnum) != -1 12 exec(a:pfx.'close') 13 return 14 endif 15 endfor 16 if a:pfx == 'l' && len(getloclist(0)) == 0 17 echohl ErrorMsg 18 echo "Location List is Empty." 19 return 20 endif 21 let winnr = winnr() 22 exec(a:pfx.'open') 23 if winnr() != winnr 24 wincmd p 25 endif 26 endfunction