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:
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?
A tab page is a page with one or more windows with a label (aka tab) at the top. Steps: Open Vim with any file or just Vim: $ vim file1. Type the contents of file and get into command mode (Press Esc )
To easily change a tab-based indent to use spaces instead when 'noexpandtab' is set, you can temporarily set 'expandtab' and use :retab with a range. For example, to convert only the current line to use spaces, use :. retab .
A buffer is an area of Vim's memory used to hold text read from a file. In addition, an empty buffer with no associated file can be created to allow the entry of text. The :e filename command can edit an existing file or a new file.
Stop, stop, stop.
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.
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.
Instead:
:set hidden
:bn
, :bp
, :b #
, :b name
, and ctrl-6
to switch between buffers. I like ctrl-6
myself (alone it switches to the previously used buffer, or #ctrl-6
switches to buffer number #
).:ls
to list buffers, or a plugin like MiniBufExpl or BufExplorer.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With