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

Jak*_*ake 2 vim

有没有办法让vim在新选项卡中打开文件,如果它尚未打开,或打开包含它的选项卡(如果有)?我知道:tab drop file只有用于vim的GUI版本,我需要它用于CLI版本.

Jak*_*ake 5

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

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
Run Code Online (Sandbox Code Playgroud)