Created
October 31, 2012 03:40
-
-
Save tacahiroy/3984661 to your computer and use it in GitHub Desktop.
Vim: toggle quickfix window
This file contains 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
" 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