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


当前回答

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

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

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

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

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

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

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

其他回答

停,停,停。

这不是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的插件,一旦安装和配置,您将能够以与选项卡几乎相同的方式使用缓冲区,而不会丢失任何功能。

相关: 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

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

我使用像标签一样的缓冲区,使用BufExplorer插件和一些宏:

" CTRL+b opens the buffer list
map <C-b> <esc>:BufExplorer<cr>

" gz in command mode closes the current buffer
map gz :bdelete<cr>

" g[bB] in command mode switch to the next/prev. buffer
map gb :bnext<cr>
map gB :bprev<cr>

使用BufExplorer,你不会在顶部有一个标签栏,但另一方面,它节省了屏幕上的空间,此外,你可以有无限的文件/缓冲区打开,缓冲区列表是可搜索的…