How do you automatically remove the preview window after autocompletion in Vim?
Solution 1
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
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
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
I don't know how to close it automatically, but you can type
:pclose
to close the scratch preview manually.
Solution 5
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
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on April 14, 2020Comments
-
Admin about 4 years
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 withcompleteopt
but to no avail. -
Ben about 12 yearsThis seems to break the command edit window for me (q: or q/). I added another check: && bufname("%") != "[Command Line]" to both lines
-
idbrii almost 12 years@Ben: Woah how did I not see your comment before posting this question. The answer I got from there was to change
pclose
tosilent! pclose
. -
Lubulos almost 12 yearsThanks to both gotgenes and pydave. Your tricks work perfectly!
-
duleshi almost 10 yearsI upvote this answer because it's a hint that the YouCompleteMe plugin has a g:ycm_autoclose_preview_window_after_insertion option.
-
Andy Hayden over 9 years@duleshi exactly what I was looking for!
-
duleshi over 9 years@AndyHayden Glad I can help! That's what I left the comment for!
-
Peter Rincker over 9 years
CompleteDone
was added in version 7.4. This method should be preferred overCursorMovedI
/InsertLeave
approach. -
David Woods about 9 yearsthank you @duleshi that's exactly what I needed as well!
-
DBedrenko over 8 years@PeterRincker I prefer the window not to close on completion (because I want to see the documentation as I'm typing in the arguments), so I will be using the
InsertLeave
line. -
Wtower about 8 yearsCou you please care to explain more?
-
nerdwaller about 8 yearsThis doesn't actually answer the question, this keeps the preview window from ever popping up, not being dismissed after completion. Note that the OP did say they tried "completeopt" as well.
-
Mahdi mehrabi over 3 yearsthis is amazing :)