繁体   English   中英

在vim中,如何在新选项卡中打开文件或切换到包含它的选项卡(如果已打开)?

[英]In vim, how can I open a file in a new tab or switch to the tab that contains it if it is already open?

有没有办法让vim在新标签中打开一个文件,如果它尚未打开,或打开包含它的标签,如果有的话? 我知道有:tab drop file但这仅适用于vim的GUI版本,我需要它用于CLI版本。

我必须为它创建自己的命令:

command! -complete=file -nargs=1 Open call Open(<f-args>)
function! Open (file)
    let b = bufnr(a:file)
    for t in range(tabpagenr("$"))
        let a = tabpagebuflist(t + 1)
        for i in a
            if i == b
                exec "tabn " . (t + 1)
                return
            endif
        endfor
    endfor
    if bufname("%") == "" && !&modified
        exec "e " . fnameescape(a:file)
        return
    endif
    exec "tabe " . fnameescape(a:file)
endfunction

暂无
暂无

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

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