如何在 Vim 自动完成后自动删除预览窗口?

发布于 2024-09-06 22:57:05 字数 282 浏览 1 评论 0原文

我正在使用 omnifunc=pythoncomplete。自动完成单词(例如,os.)时,我会按预期获得符合条件的类成员和函数的列表,以及包含有关所选成员的文档的暂存缓冲区预览窗口或函数。这很棒,但是选择我想要的功能后,预览窗口仍然存在。

我可以用 :pc 摆脱它,但我希望它在我选择我的函数后自动消失,就像 Eclipse 一样。我已经尝试过 completeopt 但无济于事。

I'm using omnifunc=pythoncomplete. When autocompleting a word (e.g., os.<something>), I get the list of eligible class members and functions, as expected, as well as a scratch buffer preview window with documentation about the selected member or function. This is great, but after selecting the function I want, the preview window remains.

I can get rid of it with :pc, but I'd like it just to automatically disappear after I've selected my function, a la Eclipse. I've played around with completeopt but to no avail.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

猛虎独行 2024-09-13 22:57:05

将以下内容放入您的 vimrc 中:

" If you prefer the Omni-Completion tip window to close when a selection is
" made, these lines close it on movement in insert mode or when leaving
" insert mode
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
autocmd InsertLeave * if pumvisible() == 0|pclose|endif

Put the following in your vimrc:

" If you prefer the Omni-Completion tip window to close when a selection is
" made, these lines close it on movement in insert mode or when leaving
" insert mode
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
橘味果▽酱 2024-09-13 22:57:05

尽管已经有一个可接受的答案,但我直接从文档中找到了这个答案,该答案适用于任何存在此问题的插件。

autocmd CompleteDone * pclose

Even though there is already an accepted answer I found this directly from the docs which will work for any plugin that is having this issue.

autocmd CompleteDone * pclose
ゃ人海孤独症 2024-09-13 22:57:05

如果您安装了 supertab 插件,则有一个名为 supertab-closepreviewonpopupclose 的选项。

将以下内容放入您的 .vimrc 中:

let g:SuperTabClosePreviewOnPopupClose = 1

If you have the supertab plugin installed, there is an option called supertab-closepreviewonpopupclose.

Put the following in your .vimrc:

let g:SuperTabClosePreviewOnPopupClose = 1
夜深人未静 2024-09-13 22:57:05

我不知道如何自动关闭它,但你可以输入

:p关闭

手动关闭暂存预览。

I don't know how to close it automatically, but you can type

:pclose

to close the scratch preview manually.

屌丝范 2024-09-13 22:57:05

您可以添加以下映射以使某些键尝试关闭预览窗口。

inoremap <space> <C-O>:wincmd z<CR><space>
inoremap ( <C-O>:wincmd z<CR>(
inoremap ) <C-O>:wincmd z<CR>)
inoremap , <C-O>:wincmd z<CR>,
inoremap <CR> <C-O>:wincmd z<CR><CR>
inoremap <esc> <esc>:wincmd z<CR>

在插入模式下完成后,您还可以使用自动命令关闭预览窗口:

augroup GoAwayPreviewWindow
autocmd! InsertLeave * wincmd z
augroup end

You could throw in the following mappings to have certain keys try to close the preview window.

inoremap <space> <C-O>:wincmd z<CR><space>
inoremap ( <C-O>:wincmd z<CR>(
inoremap ) <C-O>:wincmd z<CR>)
inoremap , <C-O>:wincmd z<CR>,
inoremap <CR> <C-O>:wincmd z<CR><CR>
inoremap <esc> <esc>:wincmd z<CR>

You could also use autocommands to close the preview window when you're finished in insert mode:

augroup GoAwayPreviewWindow
autocmd! InsertLeave * wincmd z
augroup end
公布 2024-09-13 22:57:05

我知道这个问题很老了,但是经过几天的寻找“干净”的解决方案后,我刚刚找到了完成这项工作的 CompleteDone 自动功能:

au CompleteDone * pclose

I know this question is very old, but after days of looking for a "clean" solution I just found the CompleteDone autofunction that does the job:

au CompleteDone * pclose
北城孤痞 2024-09-13 22:57:05

您可以在 .vimrc 中输入:

set completeopt-=preview

You can type that in the .vimrc:

set completeopt-=preview
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文