Skip to content

Advanced Configuration

savchenko edited this page Jun 22, 2024 · 18 revisions

Buffer selector

Creates a window with the list of all opened (not necessarily loaded) buffers and automatically sets its size to fit the content.

Think about a nice selector for :ls

require('fzfx').setup({

    buffers = {

        fzf_opts = {
            '--info=hidden',
            '--padding=0',
            '--header=',
            '--preview-window=hidden'
        },

        win_opts = function()

            local bufs_fn_len = {}
            local max_len = 0

            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)
                    buf_nm = vim.fn.fnamemodify(buf_nm, ":.")
                    if buf_listed then
                        if buf_nm ~= '' then
                            buf_len = string.len(buf_nm)
                            table.insert(bufs_fn_len, buf_len)
                        end
                    end
                end
            end

            for _, len in ipairs(bufs_fn_len) do
                max_len = math.max(max_len, len)
            end

            popup = {
                height = #bufs_fn_len + 3,
                width = max_len + 4,
                relative = 'win',
                zindex = 51,
            }

            return popup

        end

    }

})
Clone this wiki locally