How do you automatically remove the preview window after autocompletion in Vim?

VimAutocompletePreview

Vim Problem Overview


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.

Vim Solutions


Solution 1 - Vim

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

Solution 2 - Vim

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

Solution 3 - Vim

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

Put the following in your .vimrc:

let g:SuperTabClosePreviewOnPopupClose = 1

Solution 4 - Vim

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

> :pclose

to close the scratch preview manually.

Solution 5 - Vim

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

Solution 6 - Vim

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

Solution 7 - Vim

You can type that in the .vimrc:

set completeopt-=preview

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBen DaviniView Question on Stackoverflow
Solution 1 - VimgotgenesView Answer on Stackoverflow
Solution 2 - VimDan BradburyView Answer on Stackoverflow
Solution 3 - VimProfpatschView Answer on Stackoverflow
Solution 4 - VimAlan DongView Answer on Stackoverflow
Solution 5 - Vimtoo much phpView Answer on Stackoverflow
Solution 6 - VimresiView Answer on Stackoverflow
Solution 7 - VimmessiView Answer on Stackoverflow