DEV Community

Michael Lee 🍕
Michael Lee 🍕

Posted on

What's the difference between a pane, buffer and tab in Vim and how should they be used in one's workflow?

I still consider myself a newb when it comes to using Vim and still trying to optimize my workflow. One of those is trying to figure out what the differences are between a pane, buffer and tab in Vim and how should they be used in one's workflow?

Top comments (8)

Collapse
 
tbodt profile image
tbodt

When you open a file, the file is loaded into memory, into a buffer. I think of the buffers as basically a cache for the filesystem. If you switch to another file and then switch back, the other file is still loaded into a buffer, so it doesn't need to be reloaded off disk. A buffer also serves as a place to store your unsaved changes. There's never more than one buffer per file. I don't usually think about buffers, since they're just files cached in memory.

A pane is what actually displays the contents of a file. For me, the most common arrangement is to have one pane taking up the whole screen, displaying one file. Sometimes I split the screen, displaying one file on each half. Occasionally I open a new tab and put a file or two in it. I do this to keep the file around, so I can see it's still there and switch to it after a while.

Most of my file navigation is done with ctrl-p. I press ctrl-p, type the name of the file I want, and press enter, and the file is loaded into the current pane. I also use ctrl-] a lot, which is basically "go to definition" once you've set up ctags (gutentags ftw). I put the cursor on the name of a function, press ctrl-], and the definition of the function is loaded into the current pane.

Collapse
 
michael profile image
Michael Lee 🍕

Nice, thanks @tbodt for sharing your workflow. By CTRL-P are you referring to this?

Collapse
 
tbodt profile image
tbodt

Yep, github.com/ctrlpvim/ctrlp.vim is a maintained fork.

Thread Thread
 
michael profile image
Michael Lee 🍕

Cool, thanks, will look into it. I take it you use this versus something like NerdTree?

Thread Thread
 
tbodt profile image
tbodt

Yeah, I don't use NerdTree. I prefer to hold the structure of my project's files in my head, and just type what I want. I occasionally use netrw (vim's builtin NerdTree equivalent) to browse file trees, but more often just use the Finder.

Thread Thread
 
michael profile image
Michael Lee 🍕

Nice, yeah I've been using NerdTree but thinking of removing it. Since the use of NerdTree was to replicate my experience in Atom. But I'm finding the workflow to be a little slow.

Thread Thread
 
tbodt profile image
tbodt

Are you using NerdTree to navigate between files? Yeah, give ctrlp a try and see if it feels faster.

Thread Thread
 
michael profile image
Michael Lee 🍕

Yup, that's right. It's for file navigation. Vim isn't my first choice for text editing but always looking to improve my workflow when I do.