heavim/cfg/90-quickfix-toggle.vim

44 lines
1 KiB
VimL
Raw Normal View History

function! ToggleQuickfix(size, ...)
let l:mode = (a:0 == 0)? 2 : (a:1)
function! s:WindowCheck(mode)
if &buftype == 'quickfix'
let s:quickfix_open = 1
return
endif
if a:mode == 0
let w:quickfix_save = winsaveview()
else
if exists('w:quickfix_save')
call winrestview(w:quickfix_save)
unlet w:quickfix_save
endif
endif
endfunc
let s:quickfix_open = 0
let l:winnr = winnr()
noautocmd windo call s:WindowCheck(0)
noautocmd silent! exec ''.l:winnr.'wincmd w'
if l:mode == 0
if s:quickfix_open != 0
silent! cclose
endif
elseif l:mode == 1
if s:quickfix_open == 0
exec 'botright copen '. ((a:size > 0)? a:size : ' ')
wincmd k
endif
elseif l:mode == 2
if s:quickfix_open == 0
exec 'botright copen '. ((a:size > 0)? a:size : ' ')
wincmd k
else
silent! cclose
endif
endif
noautocmd windo call s:WindowCheck(1)
noautocmd silent! exec ''.l:winnr.'wincmd w'
endfunc
nmap <silent> <F12> :call ToggleQuickfix(0)<CR>
nmap <silent> <Leader>q :call ToggleQuickfix(0)<CR>