Get unique list of buffers, odd behaviour after update

Nothing of particular interest in the logs or :checkhealth.

That being said, I have solved this by checking the buflisted option. Here is the working function:

local bufs_fn_len = {}

for _, buf_nr in ipairs(vim.api.nvim_list_bufs()) do
    if vim.api.nvim_buf_is_valid(buf_nr) then
        local buf_listed = vim.api.nvim_get_option_value('buflisted', { buf = buf_nr })
        local buf_nm = vim.api.nvim_buf_get_name(buf_nr)
        buf_nm = vim.fn.expand(buf_nm)
        if buf_listed then
            if buf_nm ~= '' then
                buf_nm = vim.fn.substitute(buf_nm, vim.fn.getcwd(), '', 'g')
                buf_nm = vim.fn.substitute(buf_nm, vim.fn.expand('$HOME'), '~', 'g')
                buf_nm = vim.fs.basename(buf_nm)
                buf_len = string.len(buf_nm)
                table.insert(bufs_fn_len, buf_len)
            end
        end
    end
end

\o/

1 Like