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?
-
@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.Vayn– Vayn2011-05-24 16:09:22 +00:00Commented May 24, 2011 at 16:09
-
1Sorry, initially I though you were referring to the preview that netrw and also NERDTree have on files.sidyll– sidyll2011-05-24 16:32:33 +00:00Commented May 24, 2011 at 16:32
Add a comment
|
1 Answer
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.
2 Comments
Vayn
Thank you, autocmd.txt is too long so I didn't read it before. BTW what's the meaning of "&" here?
sidyll
@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