Vayn
Vayn

Reputation: 2717

How can I automatically close preview window after I move cursor to another window in Vim?

I would like the preview window disappears automatically when cursor is not in the preview window or preview window loses the focus. Is it possible?

Upvotes: 1

Views: 1514

Answers (1)

sidyll
sidyll

Reputation: 59277

You may want to have a look on autocommands. A simple example would be:

autocmd WinLeave * pc

Which calls pc (close preview window) every time you leave a window. A more involved example could use a separate function that performs extra checking:

autocmd WinLeave * call ClosePreviewWindow()

function ClosePreviewWindow()
    if &pvw
        pclose
    endif
endfunction

Check :h autocmd.txt to learn more. This file has a complete listing of autocommand events in section 5, so you can choose the one that fits better.

Upvotes: 2

Related Questions