A neovim plugin to cycle through recently used order and reopen recently closed buffers.
- Tracks recently used and recently closed buffers.
- Lists tracked buffers in a menu (
BufStackList,BufClosedList). - Navigates through tracked buffers (
BufStackNext,BufStackPrev). - Reopens closed buffers (
BufReopen). - Clears tracked and closed buffers (
BufStackClear,BufClosedClear,BufClear). - Telescope integration for reopening closed buffers (
BufStackTelescope). - Resession integration for persisting buffer state across sessions.
Using lazy.nvim:
return {
'BibekBhusal0/bufstack.nvim',
dependencies = {
'MunifTanjim/nui.nvim', -- optional: required for menu
'nvim-lua/plenary.nvim', -- optional: required to shorten path
'nvim-telescope/telescope.nvim', -- optional: required for telescope picker
'nvim-tree/nvim-web-devicons', -- optional: required for icon in telescope picker
'stevearc/resession.nvim' -- optional: for session persistence
},
opts = {
max_tracked = 16,
shorten_path = true
}
}require('bufstack').setup({
max_tracked = 16, -- Default: 16
shorten_path = true, -- Default: false
telescope_config = { -- Default: see below
sorting_strategy = 'ascending',
layout_config = {
prompt_position = 'top',
width = function(_, max_columns, _)
return math.min(max_columns, 80)
end,
height = function(_, _, max_lines)
return math.min(max_lines, 20)
end,
},
}
})To persist buffer state across sessions, use the resession extension:
require("resession").setup(extensions = {
bufstack = {}
})BufStack: Tracks the current buffer.BufStackNext: Navigates to the next tracked buffer.BufStackPrev: Navigates to the previous tracked buffer.BufStackList: Lists tracked buffers in a menu.BufClosedList: Lists recently closed buffers in a menu.BufStackTelescope: Lists recently closed buffers in telescope.BufReopen: Reopens the last closed buffer.BufStackClear: Clears the list of tracked buffers.BufClosedClear: Clears the list of closed buffers.BufClear: Clears both tracked and closed buffers lists.
vim.keymap.set('n', '<leader>bn', '<Cmd>BufStackNext<CR>')
vim.keymap.set('n', '<leader>bp', '<Cmd>BufStackPrev<CR>')
vim.keymap.set('n', '<leader>bl', '<Cmd>BufStackList<CR>')
vim.keymap.set('n', '<leader>br', '<Cmd>BufReopen<CR>')
vim.keymap.set('n', '<leader>bt', '<Cmd>BufStackTelescope<CR>')Menu of tracked buffer and recently closed buffers can be opened with commands BufStackList and BufClosedList respectively.
Keymaps in the menu are:
- j and arrow down for next item
- k and arrow up for previous item
- enter or space to select item
- esc or q to close menu
- d to remove item from list
- D to remove all items from list
- t to move item to the top of the list
- x to close buffer (only in tracked buffer menu)
Telescope picker can be opened with BufStackTelescope command.
Keymaps in telescope are:
- d to remove item from list
- D to clear all closed buffers
- t to move item to the top of the list
Note
Your other keymaps like open in split are still valid. Those keymaps also work with multiple items selected
Note
All dependencies are optional for specific feature only.
- nui.nvim ( Add this if you use commands
BufClosedListorBufStackList) - plenary.nvim (Add this if you set
shorten_pathto true) - telescope.nvim (Add this if you use command
BufStackTelescope) - nvim-web-devicons (Add this if you need icons inside telescope)
- resession.nvim (Add this for session management)
MIT