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

有些话、适合烂在心里 提交于 2020-05-09 04:36:12

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/21321357/how-can-i-cause-the-quickfix-window-to-close-after-i-select-an-item-in-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!