在 Vim 中将光标移动到另一个窗口后如何自动关闭预览窗口? [英] How can I automatically close preview window after I move cursor to another window in Vim?

查看:21
本文介绍了在 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?

推荐答案

您可能想看看自动命令.一个简单的例子是:

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

autocmd WinLeave * pc

每次离开窗口时都会调用 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

检查 :h autocmd.txt 以了解更多信息.此文件在第 5 节中有完整的自动命令事件列表,因此您可以选择更合适的一个.

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.

这篇关于在 Vim 中将光标移动到另一个窗口后如何自动关闭预览窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆