From 13cc065ec014b86369dfe4ad60d1a43fa06fd251 Mon Sep 17 00:00:00 2001 From: Igor Soarez Date: Thu, 17 Sep 2026 19:45:23 +0100 Subject: dotfiles Shell, editor and terminal configuration, the tools that go with them, and szecret, an age-based secret manager whose store lives elsewhere. History restarts here. What came before was not written to be read by anyone else, and carried machine names, addresses and an encrypted secret store; it is kept privately instead. What is left is meant to be safe on any machine, including one whose owner is not me: see CLAUDE.md for the rule it is written to. --- config/nvim/lua/plugins/fzf.lua | 148 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 config/nvim/lua/plugins/fzf.lua (limited to 'config/nvim/lua/plugins/fzf.lua') diff --git a/config/nvim/lua/plugins/fzf.lua b/config/nvim/lua/plugins/fzf.lua new file mode 100644 index 0000000..8ef0104 --- /dev/null +++ b/config/nvim/lua/plugins/fzf.lua @@ -0,0 +1,148 @@ +return { + { + "ibhagwan/fzf-lua", + dependencies = { "nvim-tree/nvim-web-devicons" }, + config = function() + local fzf = require("fzf-lua") + fzf.setup({ + defaults = { + file_icons = true, + }, + grep = { + rg_opts = table.concat({ + "--color=never", + "--no-heading", + "--with-filename", + "--line-number", + "--column", + "--smart-case", + "--glob=!.git/**", + "--glob=!package-lock.json", + "--glob=!lazy-lock.json", + "--glob=!node_modules/**", + }, " "), + }, + keymap = { + builtin = { + [""] = "toggle-help", + }, + fzf = { + ["ctrl-q"] = "select-all+accept", + }, + }, + }) + + -- General pickers + vim.keymap.set("n", "f", fzf.resume, { desc = "Resume search" }) + vim.keymap.set("n", "", fzf.files, { desc = "Find file" }) + vim.keymap.set("n", "a", fzf.live_grep, { desc = "Find text" }) + vim.keymap.set("n", "\\b", fzf.buffers, { desc = "Find buffer" }) + vim.keymap.set("n", "\\h", fzf.help_tags, { desc = "Find help" }) + vim.keymap.set("n", "\\k", fzf.keymaps, { desc = "Find keymaps" }) + vim.keymap.set("n", "t", fzf.colorschemes, { desc = "Select colorscheme" }) + + -- Git + vim.keymap.set("n", "\\g", fzf.git_status, { desc = "Find changed file" }) + + -- LSP pickers + vim.keymap.set("n", "\\r", function() + fzf.lsp_references({ includeDeclaration = false }) + end, { desc = "Find references" }) + vim.keymap.set("n", "\\c", fzf.lsp_incoming_calls, { desc = "Find incoming calls" }) + vim.keymap.set("n", "\\o", fzf.lsp_outgoing_calls, { desc = "Find outgoing calls" }) + vim.keymap.set("n", "\\d", fzf.lsp_definitions, { desc = "Find definitions" }) + vim.keymap.set("n", "\\t", fzf.lsp_typedefs, { desc = "Find type definitions" }) + vim.keymap.set("n", "\\i", fzf.lsp_implementations, { desc = "Find implementations" }) + vim.keymap.set("n", "\\s", fzf.lsp_document_symbols, { desc = "Find document symbols" }) + vim.keymap.set("n", "\\S", fzf.lsp_live_workspace_symbols, { desc = "Find workspace symbols" }) + + -- Search nvim config + vim.keymap.set("n", "\\C", function() + fzf.live_grep({ + cwd = vim.fn.expand("~/.config/nvim"), + rg_opts = "--follow " .. table.concat({ + "--color=never", + "--no-heading", + "--with-filename", + "--line-number", + "--column", + "--smart-case", + }, " "), + }) + end, { desc = "Search config" }) + + -- Custom directory picker + local function reset_lsp_workspace_folders() + local clients = vim.lsp.get_clients() + if #clients == 0 then + vim.notify("No active LSP clients found", vim.log.levels.WARN) + return + end + for _, client in ipairs(clients) do + local current_folders = client.workspace_folders or {} + for _, folder in ipairs(current_folders) do + vim.lsp.buf.remove_workspace_folder(folder.name) + end + vim.lsp.buf.add_workspace_folder(vim.fn.getcwd()) + vim.notify( + string.format("Reset workspace folders for %s to: %s", client.name, vim.fn.getcwd()), + vim.log.levels.INFO + ) + end + end + + local function build_find_dir_cmd() + local home = vim.fn.expand("~") + local homeSrc = vim.fn.expand("~/src") + local sense = "/Volumes/Sense" + local cmd = "find" + local search_paths = {} + local excluded_dirs = { + "*/cloud-copy*", + "*/node_modules*", + "*/.venv*", + "*/venv*", + } + if vim.fn.isdirectory(sense) == 1 then + table.insert(search_paths, sense) + table.insert(excluded_dirs, homeSrc) + else + table.insert(search_paths, homeSrc) + end + table.insert(search_paths, vim.fn.expand("~/.local/share/nvim")) + + local args = { cmd } + for _, path in ipairs(search_paths) do + table.insert(args, path) + end + table.insert(args, "-type") + table.insert(args, "d") + table.insert(args, "-maxdepth") + table.insert(args, "4") + for _, dir in ipairs(excluded_dirs) do + table.insert(args, "-not") + table.insert(args, "-path") + table.insert(args, dir) + end + return table.concat(args, " ") + end + + vim.keymap.set("n", "p", function() + fzf.fzf_exec(build_find_dir_cmd(), { + prompt = "Change Directory> ", + actions = { + ["default"] = function(selected) + local dir = selected[1] + vim.cmd("cd " .. vim.fn.fnameescape(dir)) + vim.opt.titlestring = vim.fn.fnamemodify(dir, ":t") + vim.opt.title = true + reset_lsp_workspace_folders() + vim.cmd("LspRestart") + print("Changed directory to: " .. dir) + end, + }, + }) + end, { desc = "Change working directory" }) + end, + }, +} -- cgit v1.2.3