One of the plugins I have installed (probably Supertab) provides a nice view of documentation for the currently highlighted item in the completion menu:

enter image description here

The (apparently) scratch buffer remains open even after I exit the completion (by pressing Enter or Space). Then, to quit it, I do <c-w>↑:q, but I find having to press Ctrl extremely annoying (one reason why I avoid splits).

What's a quick way to close this scratch buffer? Is there a native way, or do I have to write a mapping?

  • 3
    Something that might make Ctrl less annoying is remapping Caps Lock to Ctrl or swapping them if you want to keep Caps Lock available. – 8bittree Jul 29 '15 at 13:35
  • Which plugin you use for python code complete? For example jedi-vim have option g:jedi#auto_close_doc. – Alex Kroll Jul 29 '15 at 22:24
  • @AlexKroll to be honest, I have no idea. I think it might be Supertab. These are the plugins I've installed: github.com/murukeshm/vimrc/tree/master/bundle. I don't have Jedi installed. – muru Jul 30 '15 at 12:52
  • 2
    @muru g:SuperTabClosePreviewOnPopupClose (default 0) Looks like it's what you want :he supertab-closepreviewonpopupclose – Alex Kroll Jul 30 '15 at 12:59
  • @AlexKroll Yes, that did the trick, thanks! – muru Jul 31 '15 at 19:11

The top window is called the preview window. So any of <c-w>z, <c-w><c-z> or :pc[lose][!] should work.

The below is the help for :help :pclose

CTRL-W z        CTRL-W_z
:pc :pclose
:pc[lose][!]    Close any "Preview" window currently open.  When the 'hidden'
                option is set, or when the buffer was changed and the [!] is
                used, the buffer becomes hidden (unless there is another
                window editing it).  The command fails if any "Preview" buffer
                cannot be closed.  See also :close.

Another relevant help page would be :help preview-window

| improve this answer | |
  • 11
    Yay for :pc! I didn't realise that the "preview" name was special. – muru Jul 29 '15 at 3:07

For my specific case, the preview window was opened by plugins. So, I used plugin configuration to automatically close these windows.


As suggested by Alex Kroll:

let g:SuperTabClosePreviewOnPopupClose = 1


let g:ycm_autoclose_preview_window_after_insertion = 1
let g:ycm_autoclose_preview_window_after_completion = 1

If the second variable is set, the first has no effect. From the docs:

The *g:ycm_autoclose_preview_window_after_completion* option

When this option is set to '1', YCM will auto-close the 'preview' window after
the user accepts the offered completion string. If there is no 'preview' window
triggered because there is no 'preview' string in 'completeopt', this option is
irrelevant. See the |g:ycm_add_preview_to_completeopt| option for more details.

Default: '0'
  let g:ycm_autoclose_preview_window_after_completion = 0
The *g:ycm_autoclose_preview_window_after_insertion* option

When this option is set to '1', YCM will auto-close the 'preview' window after
the user leaves insert mode. This option is irrelevant if
|g:ycm_autoclose_preview_window_after_completion| is set or if no 'preview'
window is triggered. See the |g:ycm_add_preview_to_completeopt| option for more

Default: '0'
  let g:ycm_autoclose_preview_window_after_insertion = 0
| improve this answer | |

another nice option, which is relevant also in other cases, is using :only to close all other windows, including the preview:

CTRL-W o                        *CTRL-W_o* *E445*
CTRL-W CTRL-O                   *CTRL-W_CTRL-O* *:on* *:only*
    Make the current window the only one on the screen. All other
    windows are closed. For {count} see |:quit|.
| improve this answer | |

Another option that automatically closes the preview window and that should work with multiple completion plugins was suggested by deoplete's author in an issue:

autocmd InsertLeave,CompleteDone * if pumvisible() == 0 | pclose | endif

The downside is that you won't be able to focus the scratch window, so no scrolling. But for quick lookups it's the most convenient.

| improve this answer | |


if not using with YCM

let g:jedi#auto_close_doc = 0  " close preview window after completion
| improve this answer | |

You can use this plugin: bufutils.vim

It closes scratch buffers, location list, error list, etc...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.