Skip to content

Instantly share code, notes, and snippets.

@lodestone
Created January 22, 2014 18:32
Show Gist options
  • Save lodestone/8564487 to your computer and use it in GitHub Desktop.
Save lodestone/8564487 to your computer and use it in GitHub Desktop.
Quickly toggle the quickfix window off and on
" 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