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

我用的是 omnifunc=pythoncomplete。当自动完成一个单词(例如,os.<something>)时,我会得到符合条件的类成员和函数列表,正如预期的那样,还有一个缓冲区预览窗口,其中包含关于所选成员或函数的文档。这很棒,但是在选择了我想要的函数之后,预览窗口仍然保留。

我可以用 :pc去掉它,但是我希望它在我选择了我的函数后自动消失,就像 Eclipse 一样。我试过 completeopt,但是没有用。

23985 次浏览

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

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

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

Put the following in your .vimrc:

let g:SuperTabClosePreviewOnPopupClose = 1

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

:pclose

to close the scratch preview manually.

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

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

You can type that in the .vimrc:

set completeopt-=preview