]> git.rmz.io Git - dotfiles.git/commitdiff
vim: add togglelist plugin
authorSamir Benmendil <me@rmz.io>
Tue, 23 Aug 2016 08:12:41 +0000 (09:12 +0100)
committerSamir Benmendil <me@rmz.io>
Tue, 23 Aug 2016 08:12:41 +0000 (09:12 +0100)
vim/after/plugin/togglelist.vim [new file with mode: 0644]

diff --git a/vim/after/plugin/togglelist.vim b/vim/after/plugin/togglelist.vim
new file mode 100644 (file)
index 0000000..01ba8de
--- /dev/null
@@ -0,0 +1,67 @@
+" 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>