2017-04-30 31 views
2

有没有办法让vim在新选项卡中打开一个文件,如果它尚未打开,或者打开包含它的选项卡(如果有的话)?我知道有:tab drop file,但这仅适用于vim的GUI版本,我需要它用于CLI版本。在vim中,如何在新选项卡中打开文件或切换到包含它的选项卡(如果它已打开)?

+0

':drop'需要Vim'gui'选项进行编译,而不是它实际上是在GUI上运行,有没有什么帮助。 – Amadan

+0

请勿使用标签页作为文件代理。 – romainl

+0

你是什么意思? – Jake

回答

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