93

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.

Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
Ben Davini
  • 1,033
  • 1
  • 8
  • 6

7 Answers7

106

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
gotgenes
  • 38,661
  • 28
  • 100
  • 128
  • 2
    This seems to break the command edit window for me (q: or q/). I added another check: && bufname("%") != "[Command Line]" to both lines – Ben Apr 14 '12 at 20:52
  • 2
    @Ben: Woah how did I not see your comment before posting [this question](http://stackoverflow.com/q/11733388/79125). The answer I got from there was to change `pclose` to `silent! pclose`. – idbrii Jul 31 '12 at 05:27
  • 1
    Thanks to both gotgenes and pydave. Your tricks work perfectly! – Lubulos Aug 26 '12 at 17:49
82

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
Dan Bradbury
  • 2,071
  • 2
  • 21
  • 27
  • 15
    `CompleteDone` was added in version 7.4. This method should be preferred over `CursorMovedI`/`InsertLeave` approach. – Peter Rincker Jan 05 '15 at 21:49
  • 7
    @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. – DBedrenko Dec 07 '15 at 10:41
19

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

Put the following in your .vimrc:

let g:SuperTabClosePreviewOnPopupClose = 1
Profpatsch
  • 4,918
  • 5
  • 27
  • 32
  • 16
    I upvote this answer because it's a hint that the YouCompleteMe plugin has a g:ycm_autoclose_preview_window_after_insertion option. – duleshi Jul 16 '14 at 08:57
  • @AndyHayden Glad I can help! That's what I left the comment for! – duleshi Nov 19 '14 at 14:35
9

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

:pclose

to close the scratch preview manually.

Alan Dong
  • 3,981
  • 38
  • 35
1

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
resi
  • 1,738
  • 2
  • 13
  • 14
1

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
too much php
  • 88,666
  • 34
  • 128
  • 138
0

You can type that in the .vimrc:

set completeopt-=preview
Wtower
  • 18,848
  • 11
  • 103
  • 80
messi
  • 11
  • Cou you please care to explain more? – Wtower Apr 28 '16 at 07:10
  • 1
    This 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. – nerdwaller Jun 23 '16 at 03:26