+" 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> [oq :copen<cr>
+nmap <silent> ]oq :cclose<cr>
+nmap <silent> coq :call <SID>ToggleLocationList()<CR>
+nmap <silent> [ol :lopen<cr>
+nmap <silent> ]ol :lclose<cr>
+nmap <silent> col :call <SID>ToggleQuickfixList()<CR>