if lazyvim_docs then -- In case you don't want to use `:LazyExtras`, -- then you need to set the option below. vim.g.lazyvim_picker = "fzf" end ---@class FzfLuaOpts: lazyvim.util.pick.Opts ---@field cmd string? ---@type LazyPicker local picker = { name = "fzf", commands = { files = "files", }, ---@param command string ---@param opts? FzfLuaOpts open = function(command, opts) opts = opts or {} if opts.cmd == nil and command == "git_files" and opts.show_untracked then opts.cmd = "git ls-files --exclude-standard --cached --others" end return require("fzf-lua")[command](opts) end, } if not LazyVim.pick.register(picker) then return {} end local function symbols_filter(entry, ctx) if ctx.symbols_filter == nil then ctx.symbols_filter = LazyVim.config.get_kind_filter(ctx.bufnr) or false end if ctx.symbols_filter == false then return true end return vim.tbl_contains(ctx.symbols_filter, entry.kind) end return { desc = "Awesome picker for FZF (alternative to Telescope)", recommended = true, { "ibhagwan/fzf-lua", event = "VeryLazy", opts = function(_, opts) local config = require("fzf-lua.config") local actions = require("fzf-lua.actions") -- Quickfix config.defaults.keymap.fzf["ctrl-q"] = "select-all+accept" config.defaults.keymap.fzf["ctrl-u"] = "half-page-up" config.defaults.keymap.fzf["ctrl-d"] = "half-page-down" config.defaults.keymap.fzf["ctrl-x"] = "jump" config.defaults.keymap.builtin[""] = "preview-page-down" config.defaults.keymap.builtin[""] = "preview-page-up" -- Trouble if LazyVim.has("trouble.nvim") then config.defaults.actions.files["ctrl-t"] = require("trouble.sources.fzf").actions.open end -- Toggle root dir / cwd config.defaults.actions.files["ctrl-r"] = function(_, ctx) local o = vim.deepcopy(ctx.__call_opts) o.root = o.root == false o.cwd = nil o.buf = ctx.__CTX.bufnr LazyVim.pick.open(ctx.__INFO.cmd, o) end config.defaults.actions.files["alt-c"] = config.defaults.actions.files["ctrl-r"] config.set_action_helpstr(config.defaults.actions.files["ctrl-r"], "toggle-root-dir") -- use the same prompt for all local defaults = require("fzf-lua.profiles.default-title") local function fix(t) t.prompt = t.prompt ~= nil and " " or nil for _, v in pairs(t) do if type(v) == "table" then fix(v) end end end fix(defaults) local img_previewer ---@type string[]? for _, v in ipairs({ { cmd = "ueberzug", args = {} }, { cmd = "chafa", args = { "{file}", "--format=symbols" } }, { cmd = "viu", args = { "-b" } }, }) do if vim.fn.executable(v.cmd) == 1 then img_previewer = vim.list_extend({ v.cmd }, v.args) break end end return vim.tbl_deep_extend("force", defaults, { fzf_colors = true, fzf_opts = { ["--no-scrollbar"] = true, }, defaults = { -- formatter = "path.filename_first", formatter = "path.dirname_first", }, previewers = { builtin = { extensions = { ["png"] = img_previewer, ["jpg"] = img_previewer, ["jpeg"] = img_previewer, ["gif"] = img_previewer, ["webp"] = img_previewer, }, ueberzug_scaler = "fit_contain", }, }, -- Custom LazyVim option to configure vim.ui.select ui_select = function(fzf_opts, items) return vim.tbl_deep_extend("force", fzf_opts, { prompt = " ", winopts = { title = " " .. vim.trim((fzf_opts.prompt or "Select"):gsub("%s*:%s*$", "")) .. " ", title_pos = "center", }, }, fzf_opts.kind == "codeaction" and { winopts = { layout = "vertical", -- height is number of items minus 15 lines for the preview, with a max of 80% screen height height = math.floor(math.min(vim.o.lines * 0.8 - 16, #items + 2) + 0.5) + 16, width = 0.5, preview = not vim.tbl_isempty(LazyVim.lsp.get_clients({ bufnr = 0, name = "vtsls" })) and { layout = "vertical", vertical = "down:15,border-top", hidden = "hidden", } or { layout = "vertical", vertical = "down:15,border-top", }, }, } or { winopts = { width = 0.5, -- height is number of items, with a max of 80% screen height height = math.floor(math.min(vim.o.lines * 0.8, #items + 2) + 0.5), }, }) end, winopts = { width = 0.8, height = 0.8, row = 0.5, col = 0.5, preview = { scrollchars = { "┃", "" }, }, }, files = { cwd_prompt = false, actions = { ["alt-i"] = { actions.toggle_ignore }, ["alt-h"] = { actions.toggle_hidden }, }, }, grep = { actions = { ["alt-i"] = { actions.toggle_ignore }, ["alt-h"] = { actions.toggle_hidden }, }, }, lsp = { symbols = { symbol_hl = function(s) return "TroubleIcon" .. s end, symbol_fmt = function(s) return s:lower() .. "\t" end, child_prefix = false, }, code_actions = { previewer = vim.fn.executable("delta") == 1 and "codeaction_native" or nil, }, }, }) end, config = function(_, opts) require("fzf-lua").setup(opts) require("fzf-lua").register_ui_select(opts.ui_select or nil) end, keys = { { "", "", ft = "fzf", mode = "t", nowait = true }, { "", "", ft = "fzf", mode = "t", nowait = true }, { ",", "FzfLua buffers sort_mru=true sort_lastused=true", desc = "Switch Buffer", }, { "/", LazyVim.pick("live_grep"), desc = "Grep (Root Dir)" }, { ":", "FzfLua command_history", desc = "Command History" }, { "", LazyVim.pick("auto"), desc = "Find Files (Root Dir)" }, -- find { "fb", "FzfLua buffers sort_mru=true sort_lastused=true", desc = "Buffers" }, { "fc", LazyVim.pick.config_files(), desc = "Find Config File" }, { "ff", LazyVim.pick("auto"), desc = "Find Files (Root Dir)" }, { "fF", LazyVim.pick("auto", { root = false }), desc = "Find Files (cwd)" }, { "fg", "FzfLua git_files", desc = "Find Files (git-files)" }, { "fr", "FzfLua oldfiles", desc = "Recent" }, { "fR", LazyVim.pick("oldfiles", { cwd = vim.uv.cwd() }), desc = "Recent (cwd)" }, -- git { "gc", "FzfLua git_commits", desc = "Commits" }, { "gs", "FzfLua git_status", desc = "Status" }, -- search { 's"', "FzfLua registers", desc = "Registers" }, { "sa", "FzfLua autocmds", desc = "Auto Commands" }, { "sb", "FzfLua grep_curbuf", desc = "Buffer" }, { "sc", "FzfLua command_history", desc = "Command History" }, { "sC", "FzfLua commands", desc = "Commands" }, { "sd", "FzfLua diagnostics_document", desc = "Document Diagnostics" }, { "sD", "FzfLua diagnostics_workspace", desc = "Workspace Diagnostics" }, { "sg", LazyVim.pick("live_grep"), desc = "Grep (Root Dir)" }, { "sG", LazyVim.pick("live_grep", { root = false }), desc = "Grep (cwd)" }, { "sh", "FzfLua help_tags", desc = "Help Pages" }, { "sH", "FzfLua highlights", desc = "Search Highlight Groups" }, { "sj", "FzfLua jumps", desc = "Jumplist" }, { "sk", "FzfLua keymaps", desc = "Key Maps" }, { "sl", "FzfLua loclist", desc = "Location List" }, { "sM", "FzfLua man_pages", desc = "Man Pages" }, { "sm", "FzfLua marks", desc = "Jump to Mark" }, { "sR", "FzfLua resume", desc = "Resume" }, { "sq", "FzfLua quickfix", desc = "Quickfix List" }, { "sw", LazyVim.pick("grep_cword"), desc = "Word (Root Dir)" }, { "sW", LazyVim.pick("grep_cword", { root = false }), desc = "Word (cwd)" }, { "sw", LazyVim.pick("grep_visual"), mode = "v", desc = "Selection (Root Dir)" }, { "sW", LazyVim.pick("grep_visual", { root = false }), mode = "v", desc = "Selection (cwd)" }, { "uC", LazyVim.pick("colorschemes"), desc = "Colorscheme with Preview" }, { "ss", function() require("fzf-lua").lsp_document_symbols({ regex_filter = symbols_filter, }) end, desc = "Goto Symbol", }, { "sS", function() require("fzf-lua").lsp_live_workspace_symbols({ regex_filter = symbols_filter, }) end, desc = "Goto Symbol (Workspace)", }, }, }, { "folke/todo-comments.nvim", optional = true, -- stylua: ignore keys = { { "st", function() require("todo-comments.fzf").todo() end, desc = "Todo" }, { "sT", function () require("todo-comments.fzf").todo({ keywords = { "TODO", "FIX", "FIXME" } }) end, desc = "Todo/Fix/Fixme" }, }, }, { "neovim/nvim-lspconfig", opts = function() local Keys = require("lazyvim.plugins.lsp.keymaps").get() -- stylua: ignore vim.list_extend(Keys, { { "gd", "FzfLua lsp_definitions jump_to_single_result=true ignore_current_line=true", desc = "Goto Definition", has = "definition" }, { "gr", "FzfLua lsp_references jump_to_single_result=true ignore_current_line=true", desc = "References", nowait = true }, { "gI", "FzfLua lsp_implementations jump_to_single_result=true ignore_current_line=true", desc = "Goto Implementation" }, { "gy", "FzfLua lsp_typedefs jump_to_single_result=true ignore_current_line=true", desc = "Goto T[y]pe Definition" }, }) end, }, }