【发布时间】:2012-11-07 18:06:40
【问题描述】:
发出:tabnew somefile 将在当前标签右侧 的新标签中打开somefile。我可以让 Vim 在当前选项卡的左侧打开一个选项卡吗?
更新:建议的答案确实允许我在左侧打开一个新标签,但它们会破坏文件名自动完成,这是不行的。
【问题讨论】:
标签: vim tabs customization
发出:tabnew somefile 将在当前标签右侧 的新标签中打开somefile。我可以让 Vim 在当前选项卡的左侧打开一个选项卡吗?
更新:建议的答案确实允许我在左侧打开一个新标签,但它们会破坏文件名自动完成,这是不行的。
【问题讨论】:
标签: vim tabs customization
由于Vim 7.4.530 (2014),您可以在:[count]tabnew 中为[count] 使用负值来打开选项卡。要直接打开当前选项卡左侧的选项卡,请使用:
:-1tabnew
文档: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
:tabclose、:tabonly、:tabmove 也可以使用类似的功能,请参阅上面链接的提交。如果这不起作用,请使用 :version 检查您的 Vim 是否是最新的和/或使用 :help tabnew 检查文档是否与此处引用的文档相似。
【讨论】:
要利用@romainl 描述的行为,而不必求助于知道当前标签页号,请使用以下命令:
command -nargs=* -bar Tabnew :execute (tabpagenr()-1).'tabnew '.<q-args>
。注意:使用0tabnew 是完美的节省:这会达到预期目的,并使新标签成为第一个标签,即使没有数字低于 1 的标签页。
如果您确定永远不会将此命令与++opt 或+cmd 一起使用,您可以在-bar 之后使用-complete=file。注意:除了它的名称之外,它 不是 一个完成选项,因为它也可以进行文件名扩展(并且在 -nargs=1 和 glob 以太多文件名扩展的情况下显示错误)。不幸的是,文档中甚至没有提到这种行为。
【讨论】:
您可以使用[count]。假设您位于标签 #4,:3tabnew 在当前标签的左侧创建一个新标签。
但请记住,标签总是创建在当前标签或标签 #[count] 的右侧。 :3tabnew 实际上意味着“在标签 #3 之后创建一个新标签”。
【讨论】:
您可以编写自己的命令来执行此操作
:command -nargs=1 TabnewBefore exec "tabnew <args>" | exec "tabmove -1"
然后使用它
:TabnewBefore somefile
如果您希望它成为默认的“tabnew”行为,您可以这样做
:ca tabne TabnewBefore
现在,如果您在命令行上键入 tabne 并按空格键,它会执行您想要的操作,如果您想要原始行为,请键入完整命令 tabnew
您可以将这些定义放入您的 .vimrc 文件中以备将来使用
【讨论】:
TabnewBefore " 和 TabnewBefore \<C-a> 与 tabnew " 和 tabnew \<C-a> 相比。使用-bar 和<q-args> 是有充分理由的。
:tabnew 的快捷方式,所以这听起来完全正确。
tabnew 行为。顺便说一句,我没有提到,但它不允许使用不带参数的:tabnew。
E488: Trailing characters: tabmove -1。知道这意味着什么吗?