如何让 QuickFix 窗口在我选择其中的项目后关闭?

问题描述 投票:0回答:3

我的 vim 中安装了很棒的 bookmarks.vim 插件。我特别喜欢命名书签并使用 QuickFix 窗口列出它们。

在显示书签列表的代码中,我想添加一些内容,使 QuickFix 窗口在我选择一个选项后关闭。我该怎么做?

" 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
vim vim-plugin
3个回答
12
投票

覆盖快速修复窗口中使用的

<CR>
映射来选择条目:

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

注意:如果您不希望将其应用于位置列表,则需要稍微调整映射。


6
投票

在lua中:

-- close quickfix menu after selecting choice
vim.api.nvim_create_autocmd(
  "FileType", {
  pattern={"qf"},
  command=[[nnoremap <buffer> <CR> <CR>:cclose<CR>]]})

0
投票

如果上述方法均不起作用,

BufReadPost quickfix
事件也会触发。

这是 lua 代码...

vim.api.nvim_create_autocmd(
 "BufReadPost",
 { pattern = "quickfix", command = [[nnoremap <buffer> <CR <CR>:cclose<CR>]] }
)
© www.soinside.com 2019 - 2024. All rights reserved.