[英]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?
Is there a way to have vim open a file in a new tab if it isn't open already, or open the tab that contains it if it does? 有没有办法让vim在新标签中打开一个文件,如果它尚未打开,或打开包含它的标签,如果有的话? I know there is :tab drop file
but that's only for GUI versions of vim, I need it for the CLI version. 我知道有:tab drop file
但这仅适用于vim的GUI版本,我需要它用于CLI版本。
I had to create my own command for it: 我必须为它创建自己的命令:
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.