我正在编写一个
vim插件,我需要检查用户正在查看的当前选项卡是否为空.如果它不是空的,比如说用户已经在查看缓冲区或者有几个窗口,那么我想创建一个新的空选项卡并在那里处理我的插件.但如果它是空的,我想加载我的插件而不打开新标签.
我在文档中找不到合适的内容,所以任何人都知道如何做到这一点?
谢谢.
我能想到的唯一一件事是使用:windo迭代当前选项卡中的所有窗口并检查文件是否已加载.像这样的东西:
function! TabIsEmpty() " Remember which window we're in at the moment let initial_win_num = winnr() let win_count = 0 " Add the length of the file name on to count: " this will be 0 if there is no file name windo let win_count += len(expand('%')) " Go back to the initial window exe initial_win_num . "wincmd w" " Check count if win_count == 0 " Tab page is empty return 1 else return 0 endif endfunction " Test it like this: echo TabIsEmpty() " Use it like this: if TabIsEmpty() == 1 echo "The tab is empty" else echo "The tab is not empty" endif
如果唯一打开的是帮助页面或预览窗口或类似的东西,它可能会返回1,因为我不认为windo操作那些.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。