Unleash your inner root

Vim: Mastering your workspace: Tabs

In previous vim articles, I talked about buffers, and windows, and splits and all that good stuff. In those articles I mentioned that there was a right way to handle multiple buffers, and there was a wrong way. Today I’m going to talk to you about “the wrong way.”

That way…Is tabs. So vim has the ability to split windows, and have multiple buffers, and it also has the ability to use tabs. Now coming from a more traditional “gui” based frame of thought, a second tab is the natural way to handle working with multiple documents. It just feels…Right.

So let’s take a look at how that looks.



Pretty simple right?

So lets break it down:

:tabedit {file} # This opens a new tab pointed at {file}
:tabclose       # This closes the current tab
:tabn           # This goes to the next tab
:tabp           # This goes to the previous tab

Now you may be thinking. This works…Exactly how I want it to work. Two tabs, open a file in each tab… This is heaven. This is what I’ve been missing all my life! If you had that thought, then guess what? As I said in my previous article about windows, YOU SHOULD FEEL BAD. Here is why: You are thinking in terms of a gui. You are thinking 1 file to 1 window. That is not the case. Did you forget about buffers already?

Buffers ALREADY gave you that functionality, they just didn’t give you a little mark at the top telling you your other buffer was there. here is the thing. With tabs, you could have the same buffer open in 7 different tabs. Because the BUFFER is what matters. Instead of opening 7 tabs, and doing tabn, tabp, You could have 7 buffers open, WITHOUT tabs, because the same buffers are available to ALL tabs, the tabs don’t divide buffers. Then you just :bn, or :bp. Giving you the SAME functionality, without clutter on your screen. Remember. A buffer is an open copy of a file stored into memory. A WINDOW is a view of said buffer…. What then do you use tabs for? What task have tabs been assigned by divine right?

Easy. Tabs are COLLECTIONS of WINDOWS. I showed you how to do splits before. What if you are working on several files, and in different cases different sets of splits and window sizes were important in different moments? Do you take the time to resize your splits everytime you need them? Heck no! you make a tab with your window preferences and switch between them!

For example, let’s say you are working on a main document, that for the most part is all you really care about, but every now and again, you need to copy/reference text between two additional documents…

Tab 1 you leave with a single window looking at your primary buffer. Tab 2 you split into 3 separate windows looking at 3 separate buffers…Like SO!



Then you can switch between those two configurations easily by simply doing :tabn, or :tabp,

You can also issue:

:tabs   #Lists all tabs and their respective buffers

Tab List

So that’s really the key. It’s hard to think of “buffers” as being what you would normally use “tabs” for in a graphical world, but if you can overcome that hump, it will give you an incredibly level of flexibility that will make all the other geeks cry in the corner like chumps.


Brandon.Graves • April 23, 2016

Previous Post

Next Post

Leave a Reply

Your email address will not be published / Required fields are marked *

%d bloggers like this: