我已经看到了在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?


当前回答

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).

其他回答

停,停,停。

这不是Vim标签的设计用途。事实上,它们的名字是错的。更好的名字应该是“viewport”或“layout”,因为这就是标签的含义——它是所有现有缓冲区窗口的不同布局。

试图将Vim转换为1个tab == 1缓冲区是徒劳的。Vim不知道也不关心,它不会在所有命令上都尊重它——特别是任何使用快速修复缓冲区的命令(:make、:grep和:helpgrep是首先想到的缓冲区)都会很高兴地忽略制表符,而且您无法阻止这种情况。

而不是:

:设置隐藏 如果您还没有这个集合,那么就这样做。它使vim像地球上所有其他多文件编辑器一样工作。你可以编辑在某个窗口中不可见的缓冲区。 使用:bn,:bp,: b#,:b name和ctrl-6来切换缓冲区。我自己喜欢ctrl-6(单独切换到以前使用的缓冲区,或者#ctrl-6切换到缓冲区编号#)。 使用:ls列出缓冲区,或者像MiniBufExpl或BufExplorer这样的插件。

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

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

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).

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

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

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

相关: Vim:全局标记可以切换标签,而不是当前标签中的文件?

也许有助于解决OP的一小部分问题:

    nno \ <Cmd>call To_global_mark()<cr>
    fun! To_global_mark()
       -tab drop /tmp/useless.md
        exe 'normal! `' .. toupper(input("To global mark: "))
    endf