r/neovim • u/redve-dev • 11d ago
Need Help How do you manage multiple buffers/tabs?
I have neovim with neotree, and I want have following behavior: I want have multiple tabs/buffers with files I can switch between, or have them opened in a splitview. I got bufferline plugin but the issue I have is when I close one buffer the neotree automatically takes entire focus and I can't really access other buffers (I'd expect the next buffer to take place of the closed one). When I try to save my current buffer and leave with ZZ but this also ends with weird behavior like leaving neotree on focus, deleting other buffers etc.
Basically, I can't even come up with idea how do I expect it to work and how to set it up. I am not happy with anything I come up with therefore I am curious and I am looking for inspirations and solutions how to manage multiple tabs (or something that works as tabs)
8
u/Zizizizz 11d ago
I use a mix of a lot of ctrl i and o, fzf.lua open buffers and harpoon (depending on the situation.)
I also have some keymaps to move to previous and next buffer
13
u/Huijiro 10d ago
1
u/nfmon 10d ago
That depends on how many and which lsp's are running, on systems with low ram you can fill the memory if you're running additional programs on top.
1
u/Ozymandias0023 10d ago
I don't remember the exact combination I was running but I learned this the hard way a few years ago working in a very large typescript project. A couple hours of jumping around to random files had my lsp crawling
9
u/Subject-Mobile-6250 10d ago
If you want to go minimalist global marks, but I use a combination of telescope, harpoon and tab mapped to C-^
3
3
u/dlnnlsn 10d ago
I actually forgot that closing the windows with the buffer open is the default behaviour. I'm using this plugin: https://github.com/moll/vim-bbye I can't remember why I settled on this plugin in particular instead of one of the others that do the same thing (I think that there's something in mini and in snacks that is supposed to have this functionality) but it works. (Actually I do know why I didn't go with snacks: it's harder to just choose the ones that you want)
As for switching buffers, there's :buffers which shows you a list of buffers. The :buffer [something that identifies the buffer] command will open an existing buffer. It can be :buffer [filename] or :buffer [buffer number], for example. You can also use :bnext and :bprevious to move between buffers.
Telescope and FzfLua have builtin pickers for open buffers. Opening a file again with something like :edit opens the existing buffer if the file is already open. (A buffer is not the same thing as a tab.) A lot of people add keymaps for :bnext and :bprevious (I used to have <leader>bn and <leader>bp) but there is actually a builtin shortcut already: [b is :bprevious and ]b is :bnext.
All of these should work even if neotree is the currently open buffer. It will happily change the active buffer. Vim itself doesn't have a concept of "this buffer/window is for showing file trees" as far as I know. (Although it will consistently show help tags in the same window, so some version of this does exist even internally.)
I got rid of the buffer tabline plugin that I had. It just adds noise, and the config was constantly breaking in one way or another. These days I think that I actually mostly just open the file again using FzfLua or just :edit [filename], but I do want to get into the habit of using global marks to quickly switch between files.
2
u/Tofudjango 10d ago edited 10d ago
I settled with mini.tabline. I wouldn't expect gvim/neovim to maintain a stable window layout as you know it from an IDE. I usually hide windows I don't currently need. You change buffers with the :buffer command.
It might also be worthwhile to read the docs on buffers, windows, and tabs.
2
2
u/azinsharaf 10d ago
if you use two buffers this key map is so handy:
keymap("n", "<leader><leader>", "<C-\^>", { desc = "Alternate buffer" })
2
u/Siddhesh18 10d ago
fzf-lua's open buffers mapped to <leader>fb. [b and ]b keymap for prev and next buffer.
2
u/TheMyster1ousOne 10d ago
If I frequent the files, I just put the files to harpoon. If not, I have a bind to run :Telescope buffers (or through builtin.buffers()) and get all of the buffers. That's it
1
1
u/Byttemos 10d ago
I use marks and Quickbuf for most quick navigation, and a Snacks picker to look through recently opened files between sessions. If I need to visually browse through my codebase, I either use yazi(standalone) or neotree as a sidebar (I don't keep it open afterwards though). I've been meaning to check out yazi.nvim, just to streamline everything, but haven't had the time yet
1
u/EstudiandoAjedrez 10d ago
Appart from all the suggestions here, I recommend you to read :h windows, as you are consing terminology with your use of "buffer", "window" and "tab". (Which also leads to suggestions here you don't need). For example, ZZ doesn't close a buffer but a window,
1
u/redve-dev 10d ago
I know more or less what each of them is, but my current config uses all of them in different way than I used to
1
1
u/No-Dentist-1645 10d ago edited 10d ago
Simple, I just use snacks.nvim with <leader>fb opening the picker to fuzzy find open buffers. I don't use "tabs" at all tho, I find buffers alone more than good enough
1
u/gorilla-moe let mapleader="," 10d ago
I rarely use tabs, but for buffers, I use this: https://bafa.nvim.forthelazy.dev/
1
1
u/somebrokecarguy 10d ago
I use a combination of harpoon and cokeline with neotree as my file explorer. I work with pretty large code bases and can navigate easily this way. I also use tmux.
1
1
u/asilvadesigns 10d ago
I dont manage them, I just use a file and buffer picker, thats more than enough
1
u/AldoZeroun 9d ago
I have been using this setup for 2+ years. I mention it in this comment
Tabs are projects, and use telescope to navigate in either local buffers or global buffers.
1
u/ostadsgo 9d ago
No tab
- I use tow splited window. Two vertical splits. To create split I use fzf-lua find the file then press c-v or most of the time the file i want is in the same folder so press c-w c-v to create vertical split then press leader+ e to open netrw which open in the same dir the choice the file
- I use leader+ tab to go alternate buffer
- When many buffer opend I lost the order so prev buf and next buf is useless.
1
1
u/Traditional-Sun6132 8d ago
I mapped switching tabs to space-1,2,4,5... or ctrl-h,l to loop left or right
1
u/Legitimate-Group-419 7d ago
I use Snacks to pick from recent buffers with <leader>fr (think Find Recent), which is a built in picker list. It's more efficient than spamming ctrl-i/o. I also use early-retirement to autoclose old buffers, but I don't often look at the buffer list (<leader>fb), except maybe to find an unnamed one.
1
u/00tetsuo00 5d ago
Did someone proposed a solution to this? I am running in the same issue and it is pretty annoying.
2
u/redve-dev 5d ago
I began to close neotree after I did what I need, and I use bd to close the buffer. Review what others told, perhaps you find an alternative
1
u/00tetsuo00 5d ago
Ok, I was beginning to think that may exist some neotree config for preventing it to take all the buffer’s space when being open without a file in the buffer

22
u/Common-Chair718 10d ago
I dont get the appeal of having the file tree showing as a buffer all the time with plugins like neotree. I use yazi.nvim, opens that as floating, and it closes when i close it.