92

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?

6
  • 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
    Commented Jul 29, 2015 at 13:35
  • Which plugin you use for python code complete? For example jedi-vim have option g:jedi#auto_close_doc.
    – Alex Kroll
    Commented Jul 29, 2015 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
    Commented Jul 30, 2015 at 12:52
  • 2
    @muru g:SuperTabClosePreviewOnPopupClose (default 0) Looks like it's what you want :he supertab-closepreviewonpopupclose
    – Alex Kroll
    Commented Jul 30, 2015 at 12:59
  • @AlexKroll Yes, that did the trick, thanks!
    – muru
    Commented Jul 31, 2015 at 19:11

6 Answers 6

99

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
CTRL-W CTRL-Z   CTRL-W_CTRL-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

1
  • 14
    Yay for :pc! I didn't realise that the "preview" name was special.
    – muru
    Commented Jul 29, 2015 at 3:07
35

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

Supertab

As suggested by Alex Kroll:

let g:SuperTabClosePreviewOnPopupClose = 1

YouCompleteMe

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
details.

Default: '0'
>
  let g:ycm_autoclose_preview_window_after_insertion = 0
6

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

:on[ly][!]
:{count}on[ly][!]
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|.
4

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.

0

Jedi

if not using with YCM

let g:jedi#auto_close_doc = 0  " close preview window after completion
0

You can use this plugin: bufutils.vim

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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