A neovim plugin to cycle through recently used order and reopen recently closed buffers.
BufStackList, BufClosedList).BufStackNext, BufStackPrev).BufReopen).BufStackClear, BufClosedClear, BufClear).BufStackTelescope).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
'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:
Telescope picker can be opened with BufStackTelescope command.
Keymaps in telescope are:
[!NOTE] All dependencies are optional for specific feature only.
BufClosedList or BufStackList)shorten_path to true)BufStackTelescope)MIT