Order buffers by recency in mini.pick #1912
-
Contributing guidelines
Module(s)mini.pick QuestionHey folks, Is there a way to order the buffers by recency in the built-in picker somehow? Has anyone done that? In telescope it used to just work, not sure if it's just simple ordering by their Ids or something. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I vaguely remember it being asked somewhere here, but can not find it. There is no built-in way to do it and requires writing custom source/picker. The reason for this is to limit complexity (both in implementation and configuration) and to reuse You can have custom picker that sorts buffers by "recency" with something like this (use later with require('mini.pick').setup()
MiniPick.registry.my_buffers = function()
local items, cwd = {}, vim.fn.getcwd()
for _, buf_info in ipairs(vim.fn.getbufinfo()) do
if buf_info.listed == 1 then
local name = vim.fs.relpath(cwd, buf_info.name) or buf_info.name
table.insert(items, { text = name, bufnr = buf_info.bufnr, _lastused = buf_info.lastused })
end
end
table.sort(items, function(a, b) return a._lastused > b._lastused end)
local show = function(buf_id, items_to_show, query)
MiniPick.default_show(buf_id, items_to_show, query, { show_icons = true })
end
local opts = { source = { name = 'Buffers', items = items, show = show } }
return MiniPick.start(opts)
end |
Beta Was this translation helpful? Give feedback.
I vaguely remember it being asked somewhere here, but can not find it.
There is no built-in way to do it and requires writing custom source/picker. The reason for this is to limit complexity (both in implementation and configuration) and to reuse
:buffers
output directly (as it has some of the work done in filtering/sorting buffers and formatting their names).You can have custom picker that sorts buffers by "recency" with something like this (use later with
:Pick my_buffers
):