Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I cause the QuickFix window to close after I select an item in it?

Tags:

vim

vim-plugin

I got the wonderful bookmarks.vim plugin to my vim. I especially like the named bookmarks and using the QuickFix window to list them.

In the code to show the bookmark list I'd like to add something that causes the QuickFix window to close after I select a choice. How do I do that?

" Open all bookmarks in the quickfix window
command! CopenBookmarks call s:CopenBookmarks()
function! s:CopenBookmarks()
let choices = []

for [name, place] in items(g:BOOKMARKS)
let [filename, cursor] = place

call add(choices, {
\ 'text': name,
\ 'filename': filename,
\ 'lnum': cursor[1],
\ 'col': cursor[2]
\ })
endfor

call setqflist(choices)
copen
endfunction
like image 798
Wes Miller Avatar asked Dec 26 '22 14:12

Wes Miller


1 Answers

Override the <CR> mapping that is used in the quickfix window to select an entry:

:autocmd FileType qf nnoremap <buffer> <CR> <CR>:cclose<CR>

Note: If you don't want this applied to location lists, you need to tweak the mapping a bit.

like image 101
Ingo Karkat Avatar answered Dec 28 '22 09:12

Ingo Karkat