From e4fa75f0c33fdffa8ca56107ddd3869d59a82898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9ana=20=E6=B1=9F?= Date: Fri, 4 Jul 2025 10:28:26 +0200 Subject: [PATCH] nvim: make search remember last query and easy replacement of / and ? --- .config/nvim/after/plugin/telescope.lua | 33 ++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/.config/nvim/after/plugin/telescope.lua b/.config/nvim/after/plugin/telescope.lua index e065db53..a29c77aa 100644 --- a/.config/nvim/after/plugin/telescope.lua +++ b/.config/nvim/after/plugin/telescope.lua @@ -3,6 +3,7 @@ local actions = require("telescope.actions") local themes = require("telescope.themes") local config = require("telescope.config") local builtin = require("telescope.builtin") +local state = require("telescope.state") -- Clone the default Telescope configuration local vimgrep_arguments = { unpack(config.values.vimgrep_arguments) } @@ -21,8 +22,8 @@ telescope.setup { [""] = actions.close, }, i = { - [""] = actions.cycle_history_prev, - [""] = actions.cycle_history_next, + [""] = actions.cycle_history_prev, + [""] = actions.cycle_history_next, }, }, layout_config = { height = 0.4 }, @@ -35,13 +36,39 @@ telescope.setup { current_buffer_fuzzy_find = { layout_config = { height = 0.8 }, }, + lsp_references = { + layout_config = { height = 0.8 }, + }, + live_grep = { + layout_config = { height = 0.8 }, + }, + resume = { + initial_mode = "normal", + }, }, } -- Enable telescope fzf native, if installed pcall(require("telescope").load_extension, "fzf") -vim.keymap.set("n", "/", builtin["current_buffer_fuzzy_find"]) +-- Waiting for better state management upstream +-- Currently we have to wire the state ourselves +local buffer_picker = nil +local init_buffer_picker = function() + builtin["current_buffer_fuzzy_find"]() + local cached_pickers = state.get_global_key("cached_pickers") or {} + buffer_picker = cached_pickers[1] +end +local cached_buffer_picker = function() + if buffer_picker == nil then + init_buffer_picker() + else + builtin.resume { picker = buffer_picker } + end +end +vim.keymap.set("n", "/", init_buffer_picker) +vim.keymap.set("n", "?", cached_buffer_picker) + vim.keymap.set("n", "/", builtin["find_files"]) -- vim.keymap.set("n", "g/", builtin["git_files"]) vim.keymap.set("n", "?", builtin["help_tags"])