From 3f5e236fe5aa473124fa3bf6b75d1b343617fd1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9ana=20=E6=B1=9F?= Date: Tue, 8 Jul 2025 13:37:10 +0200 Subject: [PATCH] nvim: update telescope --- .config/nvim/after/plugin/telescope.lua | 57 ++++++++++++------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/.config/nvim/after/plugin/telescope.lua b/.config/nvim/after/plugin/telescope.lua index 8e814ccd..bb501ddf 100644 --- a/.config/nvim/after/plugin/telescope.lua +++ b/.config/nvim/after/plugin/telescope.lua @@ -9,7 +9,7 @@ local state = require("telescope.state") local vimgrep_arguments = { unpack(config.values.vimgrep_arguments) } table.insert(vimgrep_arguments, "--hidden") -- search hidden -table.insert(vimgrep_arguments, "--glob") -- ignore git +table.insert(vimgrep_arguments, "--glob") -- ignore git table.insert(vimgrep_arguments, "!**/.git/*") telescope.setup { @@ -29,7 +29,7 @@ telescope.setup { [""] = actions.cycle_history_next, }, }, - layout_config = { height = 0.4 }, + layout_config = { height = 0.5 }, borderchars = { "", "", "", "│", "", "", "", "" }, }, pickers = { @@ -37,7 +37,6 @@ telescope.setup { find_command = { "rg", "--files", "--hidden", "--glob", "!**/.git/*" }, }, current_buffer_fuzzy_find = { - layout_config = { height = 0.6 }, mappings = { n = { ["n"] = actions.move_selection_next, @@ -46,11 +45,14 @@ telescope.setup { }, }, lsp_references = { - layout_config = { height = 0.6 }, + layout_config = { height = 0.7 }, initial_mode = "normal", }, live_grep = { - layout_config = { height = 0.6 }, + layout_config = { height = 0.7 }, + }, + buffers = { + initial_mode = "normal", }, resume = { initial_mode = "normal", @@ -61,30 +63,25 @@ telescope.setup { -- Enable telescope fzf native, if installed pcall(require("telescope").load_extension, "fzf") --- 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] +local function find_undercursor_in_buffer() + builtin["current_buffer_fuzzy_find"] { + layout_config = { height = 0.8 }, -- Already have word, no need to think + default_text = vim.fn.expand(""), + initial_mode = "normal", + } 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", "?", init_buffer_picker) -vim.keymap.set("n", "n", cached_buffer_picker) -vim.keymap.set("n", "N", cached_buffer_picker) -vim.keymap.set("n", "/", builtin["find_files"]) -vim.keymap.set("n", "?", builtin["help_tags"]) -vim.keymap.set("n", "g/", builtin["live_grep"]) -vim.keymap.set("n", "G/", function() builtin["live_grep"] { default_text = vim.fn.expand("") } end) -vim.keymap.set("n", "d", builtin["diagnostics"]) -vim.keymap.set("n", "b", builtin["buffers"]) -vim.keymap.set("n", "sp", builtin["spell_suggest"]) +-- Better than builtin / +vim.keymap.set("n", "/", builtin["current_buffer_fuzzy_find"]) +vim.keymap.set("n", "w", find_undercursor_in_buffer) + +-- Use / as prefix to avoid collision in bindings +vim.keymap.set("n", "/f", builtin["find_files"]) +vim.keymap.set("n", "/?", builtin["help_tags"]) +vim.keymap.set("n", "/g", builtin["live_grep"]) +vim.keymap.set("n", "/d", builtin["diagnostics"]) +vim.keymap.set("n", "/b", builtin["buffers"]) +vim.keymap.set("n", "/p", builtin["spell_suggest"]) + +-- for GHC +-- grep -> refine for `.hs:` files