local telescope = require("telescope") 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) } table.insert(vimgrep_arguments, "--hidden") -- search hidden table.insert(vimgrep_arguments, "--glob") -- ignore git table.insert(vimgrep_arguments, "!**/.git/*") telescope.setup { -- Workaround -- https://github.com/nvim-telescope/telescope.nvim/issues/938#issuecomment-877539724 defaults = themes.get_ivy { vimgrep_arguments = vimgrep_arguments, mappings = { n = { [""] = actions.close, }, i = { [""] = actions.cycle_history_prev, [""] = actions.cycle_history_next, }, }, layout_config = { height = 0.4 }, borderchars = { "", "", "", "│", "", "", "", "" }, }, pickers = { find_files = { find_command = { "rg", "--files", "--hidden", "--glob", "!**/.git/*" }, }, current_buffer_fuzzy_find = { layout_config = { height = 0.8 }, }, lsp_references = { layout_config = { height = 0.8 }, initial_mode = "normal", }, live_grep = { layout_config = { height = 0.8 }, }, grep_string = { layout_config = { height = 0.8 }, initial_mode = "normal", }, resume = { initial_mode = "normal", }, }, } -- 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] 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", "?", builtin["help_tags"]) vim.keymap.set("n", "g/", builtin["live_grep"]) vim.keymap.set("n", "gw", builtin["grep_string"]) -- greps current word under cursor vim.keymap.set("n", "d", builtin["diagnostics"]) vim.keymap.set("n", "b", builtin["buffers"]) vim.keymap.set("n", "sp", builtin["spell_suggest"])