Skip to content

Instantly share code, notes, and snippets.

@qstrahl
Created September 6, 2019 20:22
Show Gist options
  • Save qstrahl/121d632493e24b0ec67949730520a7f0 to your computer and use it in GitHub Desktop.
Save qstrahl/121d632493e24b0ec67949730520a7f0 to your computer and use it in GitHub Desktop.
function! s:map ()
map <buffer> <Return> <Cmd>exe 'wincmd p \|' line('.') 'cc'<CR>
endfunction
function! s:unmap ()
unmap <buffer> <Return>
endfunction
function! s:list ()
return expand('<amatch>')[0] == 'l' ? getloclist(0) : getqflist()
endfunction
autocmd! QuickFixCmdPost * if !empty(s:list()) | wincmd p | endif
autocmd! BufWinEnter * if &buftype == 'quickfix' | call s:map() | endif
autocmd! BufWinLeave * if &buftype == 'quickfix' | call s:unmap() | endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment