local utils = require("utils") local map_fzf = function(mode, key, f, options, buffer) local desc = nil if type(options) == "table" then desc = options.desc options.desc = nil elseif type(options) == "function" then desc = options().desc end if utils.SWITCH_TELE then for _, k in ipairs({ "f", "l", "g" }) do key = key:gsub("" .. k, "" .. string.upper(k)) end for _, k in ipairs({ "", "", "" }) do if key == k then key = "" .. k end end -- remap buffers if key == "," then key = ";" end end local rhs = function() local fzf_lua = require("fzf-lua") local custom = require("plugins.fzf-lua.cmds") -- use deepcopy so options ref isn't saved in the mapping -- as this can create weird issues, for example, `lgrep_curbuf` -- saving the filename in between executions if custom[f] then custom[f](options and vim.deepcopy(options) or {}) else fzf_lua[f](options and vim.deepcopy(options) or {}) end end local map_options = { silent = true, buffer = buffer, desc = desc or string.format("FzfLua %s", f), } vim.keymap.set(mode, key, rhs, map_options) end -- non "f" keys map_fzf("n", ",", "buffers", { desc = "Fzf buffers" }) map_fzf("n", "", "help_tags", { desc = "help tags" }) map_fzf("n", "", "files", { desc = "find files" }) map_fzf("n", "", "workdirs", { desc = "cwd workdirs", winopts = { height = 0.40, width = 0.60, row = 0.40, } }) map_fzf("n", "fp", "files", { desc = "plugin files", prompt = "Plugins❯ ", cwd = vim.fn.stdpath "data" .. "/lazy" }) -- only fzf map_fzf("n", "fP", "profiles", { desc = "fzf-lua profiles" }) map_fzf("n", "f0", "tmux_buffers", { desc = "tmux paste buffers" }) -- same as tele map_fzf("n", "f?", "builtin", { desc = "builtin commands" }) map_fzf("n", "ff", "resume", { desc = "resume" }) map_fzf("n", "fF", "resume", { desc = "resume" }) map_fzf("n", "fm", "marks", { desc = "marks" }) map_fzf("n", "fM", "man_pages", { desc = "man pages" }) map_fzf("n", "fx", "commands", { desc = "commands" }) map_fzf("n", "f:", "command_history", { desc = "command history" }) map_fzf("n", "f/", "search_history", { desc = "search history" }) map_fzf("n", [[f"]], "registers", { desc = "registers" }) map_fzf("n", "fk", "keymaps", { desc = "keymaps" }) map_fzf("n", "fz", "spell_suggest", { desc = "spell suggestions", -- prompt = "Spell> ", winopts = { title = " Spell ", relative = "cursor", row = 1.01, col = 0, height = 0.30, width = 0.30, } }) map_fzf("n", "fT", "tags", { desc = "tags (project)" }) map_fzf("n", "ft", "btags", { desc = "tags (buffer)" }) map_fzf("n", "fr", "grep", { desc = "grep string (prompt)" }) map_fzf("n", "fR", "grep", { desc = "grep string resume", resume = true }) map_fzf("n", "fw", "grep_cword", { desc = "grep (project)" }) map_fzf("n", "fW", "grep_cWORD", { desc = "grep (project)" }) map_fzf("n", "fv", "grep_visual", { desc = "grep visual selection" }) map_fzf("v", "fv", "grep_visual", { desc = "grep visual selection" }) map_fzf("n", "fb", "blines", { desc = "fuzzy buffer lines" }) map_fzf("n", "fB", "lgrep_curbuf", { desc = "live grep (buffer)", prompt = "Buffer❯ " }) map_fzf("n", "fl", "live_grep", { desc = "live grep (project)" }) map_fzf("n", "fL", "live_grep", { desc = "live grep resume", resume = true }) map_fzf("n", "f3", "blines", function() return { desc = "blines ", fzf_opts = { ["--query"] = vim.fn.expand("") } } end) map_fzf("n", "f8", "grep_curbuf", function() return { desc = "grep (buffer)", prompt = "Buffer❯ ", search = vim.fn.expand(""), } end) map_fzf("n", "f*", "grep_curbuf", function() return { desc = "grep (buffer)", prompt = "Buffer❯ ", search = vim.fn.expand("") } end) map_fzf("n", "fH", "oldfiles", { desc = "file history (all)" }) map_fzf("n", "fh", "oldfiles", function() return { desc = "file history (cwd)", cwd = vim.loop.cwd(), cwd_header = true, cwd_only = true, } end) map_fzf("n", "fq", "quickfix", { desc = "quickfix list" }) map_fzf("n", "fQ", "loclist", { desc = "location list" }) map_fzf("n", "fO", "highlights", { desc = "colorscheme highlights" }) map_fzf("n", "fo", "colorschemes", { desc = "colorschemes", winopts = { height = 0.45, width = 0.30 }, }) -- LSP map_fzf("n", "ll", "lsp_finder", { desc = "location finder [LSP]" }) map_fzf("n", "lr", "lsp_references", { desc = "references [LSP]" }) map_fzf("n", "ld", "lsp_definitions", { desc = "definitions [LSP]", jump_to_single_result = false }) map_fzf("n", "lD", "lsp_declarations", { desc = "declarations [LSP]" }) map_fzf("n", "ly", "lsp_typedefs", { desc = "type definitions [LSP]" }) map_fzf("n", "lm", "lsp_implementations", { desc = "implementations [LSP]" }) map_fzf("n", "ls", "lsp_document_symbols", { desc = "document symbols [LSP]" }) map_fzf("n", "lS", "lsp_workspace_symbols", { desc = "workspace symbols [LSP]" }) map_fzf("n", "la", "lsp_code_actions", { desc = "code actions [LSP]" }) map_fzf("n", "lg", "diagnostics_document", { desc = "document diagnostics [LSP]" }) map_fzf("n", "lG", "diagnostics_workspace", { desc = "workspace diagnostics [LSP]" }) -- Git map_fzf("n", "gf", "git_files", { desc = "git ls-files" }) map_fzf("n", "gs", "git_status", { desc = "git status" }) map_fzf("n", "gB", "git_branches", { desc = "git branches" }) map_fzf("n", "gt", "git_tags", { desc = "git tags" }) map_fzf("n", "gC", "git_commits", { desc = "git commits (project)" }) map_fzf({ "n", "v" }, "gc", "git_bcommits", { desc = "git commits (buffer)" }) -- Full screen git status map_fzf("n", "gS", "git_status_tmuxZ", { desc = "git status (fullscreen)", winopts = { fullscreen = true, preview = { vertical = "down:70%", horizontal = "right:70%", } } }) -- yadm repo local yadm_git_opts = { cwd_header = false, cwd = "$HOME", git_dir = "$YADM_REPO", git_worktree = "$HOME", git_config = "status.showUntrackedFiles=no", } local yadm_grep_opts = { prompt = "YadmGrep❯ ", cwd_header = false, cwd = "$HOME", cmd = "git --git-dir=${YADM_REPO} -C ${HOME} grep -i --line-number --column --color=always", rg_glob = false, -- this isn't `rg` } map_fzf("n", "yf", "git_files", vim.tbl_extend("force", yadm_git_opts, { desc = "yadm ls-files", prompt = "YadmFiles> " })) map_fzf("n", "yg", "grep_project", vim.tbl_extend("force", yadm_grep_opts, { desc = "yadm grep" })) map_fzf("n", "yl", "live_grep", vim.tbl_extend("force", yadm_grep_opts, { desc = "yadm live grep" })) map_fzf("n", "yB", "git_branches", vim.tbl_extend("force", yadm_git_opts, { desc = "yadm branches", prompt = "YadmBranches> " })) map_fzf("n", "yC", "git_commits", vim.tbl_extend("force", yadm_git_opts, { desc = "yadm commits (project)", prompt = "YadmCommits> " })) map_fzf({ "n", "v" }, "yc", "git_bcommits", vim.tbl_extend("force", yadm_git_opts, { desc = "yadm commits (buffer)", prompt = "YadmBCommits> " })) map_fzf("n", "ys", "git_status", vim.tbl_extend("force", yadm_git_opts, { desc = "yadm status", cmd = "git status -s", prompt = "YadmStatus> " })) map_fzf("n", "yS", "git_status_tmuxZ", vim.tbl_extend("force", yadm_git_opts, { desc = "yadm status (fullscreen)", prompt = "YadmStatus> ", cmd = "git -c color.status=false --no-optional-locks status --porcelain=v1", winopts = { fullscreen = true, preview = { vertical = "down:70%", horizontal = "right:70%", } } }))