1

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?

2
  • @sidyll No, I don't use Netrw. I wrote a client of twitter-like service in Vim, I use preview window to display timeline. Now I want the preview window closes automatically when cursor moves to another window. Commented May 24, 2011 at 16:09
  • 1
    Sorry, initially I though you were referring to the preview that netrw and also NERDTree have on files. Commented May 24, 2011 at 16:32

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, autocmd.txt is too long so I didn't read it before. BTW what's the meaning of "&" here?
@Vayn haha that's the only problem with Vim's help: too much information :-P The & is used to echo the option value. Any option should work. It kind of "converts" the option to a variable. You can try :echo &tw for example, which echoes the value of tw. Check :h expr-option

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.