我已经看到了在Vim中使用选项卡(使用:table,:tabnew等)的能力,以取代我目前在隐藏缓冲区的同一个窗口中打开多个文件的做法。

我想每个不同的文件,我已经打开,总是在自己的选项卡。然而,有一些事情阻碍了这一点。我如何解决这些问题:

When commands like gf and ^] jump to a location in another file, the file opens in a new buffer in the current tab. Is there a way to have all of these sorts of commands open the file in a new tab, or switch to the existing tab with the file if it is already open? When switching buffers I can use :b <part of filename><tab> and it will complete the names of files in existing buffers. <part of filename> can even be the middle of a filename instead of the beginning. Is there an equivalent for switching tabs?


当前回答

有点晚了,但很惊讶我没有在这个列表中看到以下内容:

:tab sball -这将为每个打开的缓冲区打开一个新标签。

:help switchbuf -控制缓冲区切换行为,尝试:set switchbuf=usetab,newtab。这应该意味着如果缓冲区打开,则切换到现有选项卡,如果没有打开则创建一个新选项卡。

其他回答

我也遇到了同样的问题。我希望制表符像缓冲区一样工作,但我从来没有设法让它们。我最终决定的解决方案是使缓冲区的行为像制表符!

查看名为Mini Buffer Explorer的插件,一旦安装和配置,您将能够以与选项卡几乎相同的方式使用缓冲区,而不会丢失任何功能。

Vim:帮助窗口很好地解释了“选项卡与缓冲区”的混淆。

缓冲区是文件在内存中的文本。 窗口是一个视口 在缓冲器上。 标签页是窗口的集合。

打开多个文件是在vim中使用缓冲区实现的。在其他编辑器(例如notepad++)中,这是通过选项卡完成的,所以vim中的名称选项卡可能会误导。

Windows的目的是分隔工作空间并在一个屏幕上显示多个文件(缓冲区)。在其他编辑器中,这可以通过打开多个GUI窗口并在桌面上重新排列它们来实现。

最后,在这个类比中,vim的标签页将对应多个桌面,这是不同的窗口重排。

正如vim的帮助:标签页解释了一个标签页可以被使用,当一个人想要临时编辑一个文件,但不想改变任何在当前布局的窗口和缓冲区。在这种情况下,可以使用另一个选项卡页来编辑特定的文件。

当然,您必须记住,在许多选项卡页或窗口中显示相同的文件将导致显示相同的工作副本(缓冲区)。

如果你想让缓冲区像制表符一样工作,请查看tabline插件。

它使用单个窗口,并在顶部添加一行来模拟选项卡(仅显示缓冲区列表)。这是在很久以前出现的,当时仅在GVim中支持选项卡,而在命令行vim中不支持。因为它只使用缓冲区,所以一切都与vim的其余部分很好地集成在一起。

有点晚了,但很惊讶我没有在这个列表中看到以下内容:

:tab sball -这将为每个打开的缓冲区打开一个新标签。

:help switchbuf -控制缓冲区切换行为,尝试:set switchbuf=usetab,newtab。这应该意味着如果缓冲区打开,则切换到现有选项卡,如果没有打开则创建一个新选项卡。

You can map commands that normally manipulate buffers to manipulate tabs, as I've done with gf in my .vimrc: map gf :tabe <cfile><CR> I'm sure you can do the same with [^ I don't think vim supports this for tabs (yet). I use gt and gT to move to the next and previous tabs, respectively. You can also use Ngt, where N is the tab number. One peeve I have is that, by default, the tab number is not displayed in the tab line. To fix this, I put a couple functions at the end of my .vimrc file (I didn't paste here because it's long and didn't format correctly).