Interact with this post using Mastodon or
[Plugin] Buffers tabs in neovim: barbar
Published on
Keeping your opened files organized has always been a challenge and people have developed tools to help us with this task (windows manager, windows switchers, file explorers…) but tabs are certainly one of the biggest player here. We use them everywhere from text editors to web browsers.
Neovim is no exception and offers a variety of ways to manage your buffers. My personal preference went for barbar.nvim
╭── What is barbar.nvim?
From the github page “it is a tabline plugin with re-orderable, auto-sizing, clickable tabs, icons, nice highlighting, sort-by commands and a magic jump-to-buffer mode. Plus the tab names are made unique when two filenames match.”
In one sentence you’re presented with all the features that this plugin has. It allows you to keep an eye on your open buffers by assigning tabs to them and it renders the manipulation of your files extremely convenient and efficient thanks to a very high level of customization.
Actually, this plugin is not deliver with a default configuration (though there is examples on the github page) leaving you complete freedom to come up with what works for you.
╭── Lots of features but they’re all useful
-
Re-order tabs
-
Auto-sizing tabs, fill the space when available
-
Jump-to-buffer mode: if you can switch buffers based on their order (using numbers), you may also appreciate that each buffer will be assigned a letter when opened. This letter will stay constant for the lifetime of the buffer and - by typing this single letter - you will automatically jump to its associated buffer. Smart ! By default, the letter is one found in the buffer’s name but you can change this so that letters are assigned based on usability (home row [asdfjkl;gh] first, then other rows).
-
Sort tabs automatically by directory, language, window number, or buffer number
-
Clickable & closable tabs if you can’t get rid of your mouse yet ;)
-
Unique names when filenames match
-
Pinned buffers
-
Scrollable tabs, to always show the current buffer
╭── No default mappings
As mentioned earlier, there is no default configuration for this plugin but - in addition to examples on the github page - here are the keybindings I use (in lua) in case you can get some inspiration from these:
vim.keymap.set( 'n', 'b', ':BufferPick<CR>') -- jump-to-buffer mode will wait for the letter to jump to its associated buffer
vim.keymap.set( 'n', 'bp', ':bp<CR>') -- jump to previous buffer
vim.keymap.set( 'n', 'bn', ':bn<CR>') -- jump to next buffer
vim.keymap.set( 'n', 'b1', ':BufferGoto 1<CR>') -- jump to buffer #1
vim.keymap.set( 'n', 'b2', ':BufferGoto 2<CR>') -- jump to buffer #2
vim.keymap.set( 'n', 'b3', ':BufferGoto 3<CR>') -- jump to buffer #3
vim.keymap.set( 'n', 'b4', ':BufferGoto 4<CR>') -- jump to buffer #4
vim.keymap.set( 'n', 'b5', ':BufferGoto 5<CR>') -- jump to buffer #5
vim.keymap.set( 'n', 'b6', ':BufferGoto 6<CR>') -- jump to buffer #6
vim.keymap.set( 'n', 'b7', ':BufferGoto 7<CR>') -- jump to buffer #7
vim.keymap.set( 'n', 'b8', ':BufferGoto 8<CR>') -- jump to buffer #8
vim.keymap.set( 'n', 'b9', ':BufferGoto 9<CR>') -- jump to buffer #9
vim.keymap.set( 'n', 'bb', ':enew<CR>') -- create a new empty buffer
Thanks for your read. Hope it's been useful to you.
✄ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈
More food for thoughts? Check other posts about: #(Neo)vim #(Neo)vim-Plugins