使用 Vim 的选项卡,如缓冲区 [英] Using Vim's tabs like buffers
问题描述
我已经研究了在 Vim 中使用选项卡的能力(使用 :tabe
、:tabnew
等)来替代我目前拥有许多文件的做法在隐藏缓冲区中的同一窗口中打开.
I have looked at the ability to use tabs in Vim (with :tabe
, :tabnew
, etc.) as a replacement for my current practice of having many files open in the same window in hidden buffers.
我希望我打开的每个不同文件始终位于其自己的选项卡中.但是,有些事情会阻碍这一点.我该如何解决这些问题:
I would like every distinct file that I have open to always be in its own tab. However, there are some things that get in the way of this. How do I fix these:
当
gf
和^]
之类的命令跳转到另一个文件中的某个位置时,该文件会在当前选项卡的新缓冲区中打开.有没有办法让所有这些类型的命令在新选项卡中打开文件,或者如果文件已经打开,则切换到包含文件的现有选项卡?
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?
切换缓冲区时我可以使用:b <部分文件名><tab>
它将完成现有缓冲区中的文件名.
甚至可以是文件名的中间而不是开头.是否有切换标签的等价物?
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 选项卡的设计用途.事实上,他们的名字是错误的.更好的名称是viewport"或layout",因为这就是选项卡的含义——它是现有缓冲区的所有窗口的不同布局.
This is not how Vim's tabs are designed to be used. In fact, they're misnamed. A better name would be "viewport" or "layout", because that's what a tab is—it's a different layout of windows of all of your existing buffers.
试图在 1 个选项卡 == 1 个缓冲区中击败 Vim 是徒劳的.Vim 不知道也不关心,它不会在所有命令上尊重它——尤其是任何使用 quickfix 缓冲区的东西(:make
、:grep
和 :helpgrep
是那些浮现在脑海中的)会很高兴地忽略选项卡,你无法阻止它.
Trying to beat Vim into 1 tab == 1 buffer is an exercise in futility. Vim doesn't know or care and it will not respect it on all commands—in particular, anything that uses the quickfix buffer (:make
, :grep
, and :helpgrep
are the ones that spring to mind) will happily ignore tabs and there's nothing you can do to stop that.
改为:
:设置隐藏
如果你还没有这一套,那就去做吧.它使 vim 像地球上所有其他多文件编辑器一样工作.您可以编辑在某个窗口中不可见的缓冲区.- 使用
:bn
、:bp
、:b #
、:b name
和ctrl-6
在缓冲区之间切换.我自己喜欢ctrl-6
(单独切换到之前使用的缓冲区,或者#ctrl-6
切换到缓冲区号#
). - 使用
:ls
列出缓冲区,或像 MiniBufExpl 或 BufExplorer.
:set hidden
If you don't have this set already, then do so. It makes vim work like every other multiple-file editor on the planet. You can have edited buffers that aren't visible in a window somewhere.- Use
:bn
,:bp
,:b #
,:b name
, andctrl-6
to switch between buffers. I likectrl-6
myself (alone it switches to the previously used buffer, or#ctrl-6
switches to buffer number#
). - Use
:ls
to list buffers, or a plugin like MiniBufExpl or BufExplorer.
这篇关于使用 Vim 的选项卡,如缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!