" Toggle, open or close the quickfix window. The first argument is the size " (0 for automatic), and the second argument, if present, determines which " action to perform: 0 forces the window closed, 1 opens it, and 2 toggles it. 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 command! -bar QuickfixClose call ToggleQuickfix(0, 0) command! -bar QuickfixOpen call ToggleQuickfix(0, 1) command! -bar QuickfixToggle call ToggleQuickfix(0, 2) nmap :call ToggleQuickfix(0) nmap q :call ToggleQuickfix(0)