我可以打开当前标签左侧的新标签吗?

bit*_*ask 12 vim customization tabs

发布:tabnew somefilesomefile在当前选项卡右侧的新选项卡中打开.我可以以某种方式让Vim打开当前标签左侧的标签吗?

更新:建议的答案允许我打开一个新的选项卡,但他们打破文件名自动完成,这是一个禁忌.

ZyX*_*ZyX 9

要利用@romainl描述的行为而不必求助于了解当前标签页号,请使用以下命令:

command -nargs=* -bar Tabnew :execute (tabpagenr()-1).'tabnew '.<q-args>
Run Code Online (Sandbox Code Playgroud)

.注意:它完全可以保存使用0tabnew:即使没有数字低于1的标签页,这也可以实现预期,并使新标签成为第一个标签页.

如果您确定永远不会使用此命令,++opt或者+cmd您可以-complete=file在之后使用-bar.注意:除了它的名称,它不是一个完成选项,因为它也有文件名扩展(并显示大小写中的错误-nargs=1和以太多文件名扩展的globs).不幸的是,文档中甚至没有提到这种行为.


Rob*_*b W 8

由于Vim的7.4.530(2014) ,可以使用负值用于[count]:[count]tabnew打开的选项卡.要直接在当前选项卡的左侧打开选项卡,请使用:

:-1tabnew
Run Code Online (Sandbox Code Playgroud)

文档:https://vimhelp.appspot.com/tabpage.txt.html#:tabnew

:[count]tabe[dit]                               :tabe :tabedit :tabnew
:[count]tabnew
                Open a new tab page with an empty window, after the current
                tab page.  If [count] is given the new tab page appears after
                the tab page [count] otherwise the new tab page will appear
                after the current one. 
                    :tabnew     " opens tabpage after the current one
                    :.tabnew    " as above
                    :+tabnew    " opens tabpage after the next tab page
                                " note: it is one further than :tabnew
                    :-tabnew    " opens tabpage before the current one
                    :0tabnew    " opens tabpage before the first one
                    :$tabnew    " opens tabpage after the last one
Run Code Online (Sandbox Code Playgroud)

类似的功能也可用于:tabclose,:tabonly,:tabmove,看到提交上面链接.如果这不起作用,请使用:version检查您的Vim是否是最新的和/或用于:help tabnew检查文档是否与此处引用的文档类似.