Skip to content

Instantly share code, notes, and snippets.

@tacahiroy
Created October 31, 2012 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tacahiroy/3984661 to your computer and use it in GitHub Desktop.
Save tacahiroy/3984661 to your computer and use it in GitHub Desktop.
Vim: toggle quickfix window
" quickfix
function! s:redir(cmd)
redir => res
execute a:cmd
redir END
return res
endfunction
function! s:toggle_qf_list()
let bufs = s:redir('buffers')
let l = matchstr(split(bufs, '\n'), '[\t ]*\d\+[\t ]\+.\+[\t ]\+"\[Quickfix\ List\]"')
let winnr = -1
if !empty(l)
let bufnbr = matchstr(l, '[\t ]*\zs\d\+\ze[\t ]\+')
let winnr = bufwinnr(str2nr(bufnbr, 10))
endif
if !empty(getqflist())
if winnr == -1
copen
else
cclose
endif
endif
endfunction
nnoremap <silent> qo :<C-u>silent call <SID>toggle_qf_list()<Cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment