1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 13:00:04 +08:00

Fix key binding q in quickfix windows (#3645)

close #3450
This commit is contained in:
Wang Shidong 2020-07-18 23:25:37 +08:00 committed by GitHub
parent 9a9e18e3f2
commit ca735648ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,6 +9,7 @@
let s:SYS = SpaceVim#api#import('system')
let s:JOB = SpaceVim#api#import('job')
let s:CMP = SpaceVim#api#import('vim#compatible')
"autocmds
@ -16,7 +17,7 @@ function! SpaceVim#autocmds#init() abort
augroup SpaceVim_core
au!
autocmd BufWinEnter quickfix nnoremap <silent> <buffer>
\ q :cclose<cr>:lclose<cr>
\ q :call <SID>close_quickfix()<cr>
autocmd BufEnter * if (winnr('$') == 1 && &buftype ==# 'quickfix' ) |
\ bd|
\ q | endif
@ -196,5 +197,31 @@ function! s:disable_welcome() abort
augroup END
endfunction
function! s:close_quickfix() abort
if winnr() == s:get_qf_winnr()
cclose
else
lclose
endif
endfunction
" https://vi.stackexchange.com/questions/16585/how-to-differentiate-quickfix-window-buffers-and-location-list-buffers
if has('patch-7.4-2215') " && exists('*getwininfo')
function! s:get_qf_winnr() abort
let wins = filter(getwininfo(), 'v:val.quickfix && !v:val.loclist')
" assert(len(wins) <= 1)
return empty(wins) ? 0 : wins[0].winnr
endfunction
else
let s:k_msg_qflist = '[Quickfix List]'
function! s:get_qf_winnr() abort
let buffers = s:CMP.execute('ls!')
call filter(buffers, 'v:val =~ "\\V".s:k_msg_qflist')
" :cclose removes the buffer from the list (in my config only??)
" assert(len(buffers) <= 1)
return empty(buffers) ? 0 : eval(matchstr(buffers[0], '\v^\s*\zs\d+'))
endfunction
endif
" vim:set et sw=2: