DEV Community

Using buffers, windows, and tabs efficiently in Vim

Igor Irianto on April 20, 2020

Follow @learnvim for more Vim tips and tricks! Vim has never been like most editors. I've used different editors (Notepad++, Atom, VSCode, and yes...
Collapse
 
gurdeepgss profile image
thicckWire • Edited

Is there any way we can have buffers containerized in tabs.

I mean suppose I open 3 buffers in vim.
then I create a new tab and open 3 completely new buffers in that tab.
Now if I :ls it shows all the buffers, the behaviour that I expect or think-of-as-better-one is that if I :ls in second tab, only buffers opened in that tab are shown.
And first tab buffers are only shown for the first tab on :ls.

Though it should be configurable, if one want to access buffers from the first tab then some variant of :ls or some other command should give me all the buffers so that I can use vim's default behaviour.

what do you guys think of it?
Should it be this way, as I described or should this be left to tmux+new-vim-instance?

Collapse
 
iggredible profile image
Igor Irianto

I never thought of containerizing buffer in tabs before, but that's a good point. I personally don't use Vim tabs. I may have multiple Vim instances in different Tmux windows, so they are automatically containerized.

I think it comes down to a design decision. The people who wrote Vim (Bram etc) probably decided that buffers are shared objects instead of tab-specific objects. It could've gone either way haha.

Again, this is a really good point that you brought up!

Collapse
 
konfekt profile image
konfekt

vim-ctrlspace is a plug-in to containerize buffers in tabs.

Thread Thread
 
gurdeepgss profile image
thicckWire

Will look into that.

Collapse
 
gurdeepgss profile image
thicckWire

from a users perspective I think this should be configurable, for the folks who do not have tmux available (like I on my employer's windows machine).

Or I think we could make a plugin that does this somehow. I don't know the details of it, but I think it might be possible.

Collapse
 
khalidwilliams profile image
Khalid Williams

Super helpful -- thank you!

Collapse
 
nickfun profile image
Nick F

This was useful. Getting familiar with the terms really helped me back when I was using Emacs. Now I'm learning VIM and this is a good reference.

Collapse
 
iggredible profile image
Igor Irianto

Thanks Nick! Appreciate it. If you find how I can present my article better, please feel free to put it in comment :)
Any feedback will be highly coveted.

Collapse
 
timabell profile image
Tim Abell

Use of ctrl-p with fzf to switch buffers/tabs/files is a superb tip, I'd forgotten I had that set up. So much easier & faster than :tabn etc.

Collapse
 
alexgnatrow profile image
Alex Row

Nice! Looks like it was kind of article I needed so much.
Super helpful! Thank you.

Collapse
 
axl989 profile image
Sergio Olivieri

I still don't get it. What's the practical usage of buffers?

Collapse
 
rafaelbdb profile image
Borjovsky • Edited

This is one of the best explanations I've ever seen about anything (not only VIM resources)!! The X/Y/Z axis thinking makes everything soooooo much cleaner!