naive231
naive231

Reputation: 1380

Is there a way to know `preview` window opened(existed) in vim?

In fact, I just want to write a script to toggle preview window. But it seems can't archived from any internal setting of vim.

So, as title. I want to write a script to do it. Any one knows how to check preview window is opened(or existed)?

Upvotes: 7

Views: 1312

Answers (2)

JonnyRaa
JonnyRaa

Reputation: 8038

You can add %w to your statusline config to get it to say [Preview] for the relevant window.

sample status line setting (in vimrc)

set statusline=%.50F%m%r\ %y\%w\ buffer\ %n\ %l\|%c\ [%p%%] 

see :h statusline for more info

Upvotes: 0

Hui Zheng
Hui Zheng

Reputation: 10222

Check variable previewwindow or pvw(please refer to the link). A sample code would be:

fun! previewWindowOpened
    for nr in range(1, winnr('$'))
        if getwinvar(nr, "&pvw") == 1
            " found a preview
            return 1
        endif  
    endfor
    return 0
endfun

Upvotes: 10

Related Questions