Created
January 22, 2014 18:32
-
-
Save lodestone/8564487 to your computer and use it in GitHub Desktop.
Quickly toggle the quickfix window off and on
This file contains hidden or 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 Quickfix window with <leader>q | |
function! GetBufferList() | |
redir =>buflist | |
silent! ls | |
redir END | |
return buflist | |
endfunction | |
function! ToggleList(bufname, pfx) | |
let buflist = GetBufferList() | |
for bufnum in map(filter(split(buflist, '\n'), 'v:val =~ "'.a:bufname.'"'), 'str2nr(matchstr(v:val, "\\d\\+"))') | |
if bufwinnr(bufnum) != -1 | |
exec(a:pfx.'close') | |
return | |
endif | |
endfor | |
if a:pfx == 'l' && len(getloclist(0)) == 0 | |
echohl ErrorMsg | |
echo "Location List is Empty." | |
return | |
endif | |
let winnr = winnr() | |
exec(a:pfx.'open') | |
if winnr() != winnr | |
wincmd p | |
endif | |
endfunction | |
nmap <silent> <leader>q :call ToggleList("Quickfix List", 'c')<CR> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment