]> git.rmz.io Git - dotfiles.git/blob - vim/after/plugin/togglelist.vim
vim: fix quickfix/location list confusion
[dotfiles.git] / vim / after / plugin / togglelist.vim
1 " toggle unite, quickfix list and location list
2 if exists("g:loaded_toggle_list")
3 finish
4 endif
5
6 let g:loaded_toggle_list = 1
7
8 function! s:GetBufferList()
9 redir =>buflist
10 silent! ls
11 redir END
12 return buflist
13 endfunction
14
15 function! s:ToggleLocationList()
16 for bufnum in map(filter(split(s:GetBufferList(), '\n'), 'v:val =~# "Location List"'), 'str2nr(matchstr(v:val, "\\d\\+"))')
17 lclose
18 return
19 endfor
20
21 let last = winnr('$')
22
23 try
24 Errors
25 catch
26 try
27 lopen
28 catch /E776/
29 endtry
30 endtry
31 if last == winnr('$')
32 echohl WarningMsg | echon 'No Location List' | echohl None
33 endif
34 endfunction
35
36 function! s:ToggleQuickfixList()
37 for bufnum in map(filter(split(s:GetBufferList(), '\n'), 'v:val =~ "Quickfix List"'), 'str2nr(matchstr(v:val, "\\d\\+"))')
38 if bufwinnr(bufnum) != -1
39 cclose
40 return
41 endif
42 endfor
43 let winnr = winnr()
44 copen 10
45 if winnr() != winnr
46 wincmd p
47 endif
48 endfunction
49
50
51 function! s:ToggleUnite()
52 for i in range(1, winnr('$'))
53 let name = bufname(winbufnr(i))
54 if match(name, '^\[unite\]') == 0
55 UniteClose
56 return
57 endif
58 endfor
59 UniteResume
60 endfunction
61
62 nmap <silent> [oq :copen<cr>
63 nmap <silent> ]oq :cclose<cr>
64 nmap <silent> coq :call <SID>ToggleQuickfixList()<CR>
65 nmap <silent> [ol :lopen<cr>
66 nmap <silent> ]ol :lclose<cr>
67 nmap <silent> col :call <SID>ToggleLocationList()<CR>