简体   繁体   English

如何自动关闭 vim 预览 window 后我键入:q 命令退出 window,选项卡或 vim?

[英]How to automatically close vim preview window after I type :q command to exit a window, tab or vim?

I did search, and got a cloeset answer form How can I automatically close preview window after I move cursor to another window in Vim?我做了搜索,得到了一个壁橱答案表我将 cursor 移动到 Vim 中的另一个 window 后,如何自动关闭预览 window? . . However I found it doesn't work with taglist plugin properly.但是我发现它不能正确地与 taglist 插件一起使用。

Here's the code taken from the above link:这是从上面的链接中获取的代码:

autocmd WinLeave * pc

autocmd WinLeave * call ClosePreviewWindow()
function ClosePreviewWindow()
    if &pvw
        pclose
    endif
endfunction

I'm using a vim plugin called autopreview.我正在使用一个名为 autopreview 的 vim 插件。 Gennerally it will call ptag command to open a preview window and jump back to the buffer window. Here's the problem, when it jumps from buffer window to preview window and back, it will trigger WinLeave event twice, then the preview window will be closed immediately after opened.一般会调用ptag命令打开预览window,然后跳回缓冲区window。问题来了,当它从缓冲区window跳转到预览window再返回时,会触发两次WinLeave事件,然后立即关闭预览window打开后。 So it never showed up.所以一直没有出现。 I tried to replace WinLeave with TabLeave/BufLeave, other problems occurred.我尝试用 TabLeave/BufLeave 替换 WinLeave,出现了其他问题。 So I came here for help.所以我来这里寻求帮助。

UPDATE:更新:
Maybe I should use tabclose/qa command?也许我应该使用 tabclose/qa 命令?

Have you tried using the WinEnter event instead of WinLeave?您是否尝试过使用 WinEnter 事件而不是 WinLeave? In the handler you'd check to see if you're entering the preview window and if so do nothing, otherwise check to see if the preview window is open and close it if necessary (like your code above).在处理程序中,您将检查是否正在进入预览 window,如果是则什么也不做,否则检查预览 window 是否打开并在必要时关闭它(如上面的代码)。

Edit编辑

Based on your description, in order to make this work you'll need to check to see if the previous window was the preview window. This snippet will tell you that:根据您的描述,为了完成这项工作,您需要检查之前的 window 是否是预览版 window。此代码段将告诉您:

if getwinvar(winnr("#"), "&pvw") == 1
    " do stuff, e.g. pclose
endif

What that says is, "get me the option value pvw (which happens to be window-local) for the previous window", where winnr("#") gives the window number of the previous window.它的意思是,“给我前一个窗口的选项值pvw (碰巧是窗口本地的)”,其中winnr("#")给出前一个 window 的 window 编号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM