Skip to content

Advanced Configuration

linrongbin16 edited this page Feb 26, 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 :files

require('fzfx').setup({
    buffers = {
        fzf_opts = {
            '--info=hidden --header= --padding=0'
        },
        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 = vim.api.nvim_buf_get_name(buf_nr)
                    local buf_nm = vim.fn.expand(buf)
                    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)
                        table.insert(bufs_fn_len, string.len(buf_nm))
                    end
                end
            end
            for _, len in ipairs(bufs_fn_len) do
                max_len = math.max(max_len, len)
            end
            return {
                height = #bufs_fn_len + 4,
                width = max_len + 7,
                relative = 'win',
                zindex = 51,
            }
        end
    }
}
Clone this wiki locally