summaryrefslogtreecommitdiffstats
path: root/.config/nvim/plugin/50-fzf.lua
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/plugin/50-fzf.lua')
-rw-r--r--.config/nvim/plugin/50-fzf.lua64
1 files changed, 64 insertions, 0 deletions
diff --git a/.config/nvim/plugin/50-fzf.lua b/.config/nvim/plugin/50-fzf.lua
new file mode 100644
index 0000000..e0c4ce3
--- /dev/null
+++ b/.config/nvim/plugin/50-fzf.lua
@@ -0,0 +1,64 @@
+--
+-- Fuzzy finder configuration (files, grep, buffers, help)
+--
+-- See https://github.com/ibhagwan/fzf-lua
+
+-- Avoid conflicts with the already existing fzf configuration at ~/.config/fzf/fzf.bash
+vim.env.FZF_DEFAULT_OPTS = nil
+
+local fzf = require("fzf-lua")
+
+-- Copy selected entries' paths to the clipboard (icon-stripped via entry_to_file).
+local function copy_to_clipboard(selected, opts)
+ local entry_to_file = require("fzf-lua.path").entry_to_file
+ vim.fn.setreg(
+ "+",
+ table.concat(
+ vim.tbl_map(function(sel)
+ return entry_to_file(sel, opts).path
+ end, selected),
+ "\n"
+ )
+ )
+end
+
+fzf.setup({
+ winopts = {
+ preview = {
+ layout = "flex",
+ flip_columns = 120,
+ },
+ },
+ keymap = {
+ fzf = {
+ true, -- inherit defaults
+ ["tab"] = "down", -- navigate instead of fzf's default toggle
+ ["btab"] = "up",
+ ["ctrl-y"] = "toggle", -- multi-select toggle (tab no longer does it)
+ },
+ builtin = {
+ true, -- inherit defaults
+ ["<M-/>"] = "toggle-preview", -- show/hide preview
+ ["<C-n>"] = "preview-half-page-down", -- scroll preview (Ctrl-j/k navigate)
+ ["<C-p>"] = "preview-half-page-up",
+ },
+ },
+ actions = {
+ files = { true, ["alt-y"] = copy_to_clipboard }, -- files + live_grep
+ buffers = { true, ["alt-y"] = copy_to_clipboard },
+ },
+ -- Sticky footer of keybinding hints, like --footer in ~/.config/fzf/fzf.bash.
+ fzf_opts = {
+ ["--footer"] = table.concat({
+ "Alt+Y copy to clipboard",
+ "Ctrl+Y toggle selection",
+ "Alt+/ show/hide preview",
+ }, "\n"),
+ },
+})
+
+vim.keymap.set("n", "<Leader>ff", fzf.files, { desc = "Fuzzy-find files" })
+vim.keymap.set("n", "<Leader>fg", fzf.live_grep, { desc = "Fuzzy-find files content" })
+vim.keymap.set("n", "<Leader>fb", fzf.buffers, { desc = "Fuzzy-find buffers" })
+vim.keymap.set("n", "<Leader>fh", fzf.helptags, { desc = "Fuzzy-find help tags" })
+vim.keymap.set("n", "<Leader>fr", fzf.resume, { desc = "Resume last fuzzy-find picker" })