return { "nvim-telescope/telescope.nvim", dependencies = { "nvim-lua/plenary.nvim", "nvim-tree/nvim-web-devicons", "debugloop/telescope-undo.nvim", "nvim-telescope/telescope-ui-select.nvim", { "nvim-telescope/telescope-fzf-native.nvim", build = "make" }, }, config = function() local telescope = require("telescope") local actions = require("telescope.actions") local builtin = require("telescope.builtin") local previewers = require("telescope.previewers") local previewers_utils = require("telescope.previewers.utils") -- Configuration constants local MAX_FILE_SIZE = 100000 -- Enable line numbers in telescope previews vim.api.nvim_create_autocmd('User', { pattern = 'TelescopePreviewerLoaded', callback = function() vim.wo.number = true end, }) -- Truncate large files in preview to improve performance local function truncate_large_files(filepath, bufnr, opts) opts = opts or {} filepath = vim.fn.expand(filepath) vim.uv.fs_stat(filepath, function(_, stat) if not stat then return end if stat.size > MAX_FILE_SIZE then local cmd = { "head", "-c", tostring(MAX_FILE_SIZE), filepath } previewers_utils.job_maker(cmd, bufnr, opts) else previewers.buffer_previewer_maker(filepath, bufnr, opts) end end) end -- Cache git status to avoid repeated system calls local is_inside_work_tree = {} local function smart_project_files() local cwd = vim.fn.getcwd() if is_inside_work_tree[cwd] == nil then vim.fn.system("git rev-parse --is-inside-work-tree") is_inside_work_tree[cwd] = vim.v.shell_error == 0 end local opts = is_inside_work_tree[cwd] and { show_untracked = true, hidden = true } or {} local picker = is_inside_work_tree[cwd] and builtin.git_files or builtin.find_files picker(opts) end -- Telescope setup telescope.setup({ defaults = { file_sorter = require("telescope.sorters").get_fzy_sorter, color_devicons = true, buffer_previewer_maker = truncate_large_files, initial_mode = "insert", selection_strategy = "reset", sorting_strategy = "ascending", path_display = { "truncate" }, layout_config = { prompt_position = "top", horizontal = { preview_width = 0.6, }, vertical = { mirror = false, }, }, -- Modern borderchars borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, -- Performance optimizations use_less = true, set_env = { COLORTERM = "truecolor" }, mappings = { i = { [""] = actions.move_selection_next, [""] = actions.move_selection_previous, [""] = actions.cycle_history_next, [""] = actions.cycle_history_prev, [""] = actions.smart_send_to_qflist + actions.open_qflist, [""] = false, -- Clear prompt [""] = actions.close, -- Close prompt }, n = { ["q"] = actions.close, }, }, }, pickers = { diagnostics = { initial_mode = "normal", layout_config = { preview_cutoff = 9999, }, }, buffers = { sort_mru = true, sort_lastused = true, mappings = { i = { [""] = actions.delete_buffer, }, n = { ["dd"] = actions.delete_buffer, }, }, }, find_files = { hidden = true, find_command = { "rg", "--files", "--hidden", "--glob", "!**/.git/*" }, }, }, extensions = { undo = { side_by_side = true, layout_strategy = "vertical", layout_config = { preview_height = 0.8, }, mappings = { i = { [""] = require("telescope-undo.actions").restore, }, n = { [""] = require("telescope-undo.actions").restore, ["y"] = require("telescope-undo.actions").yank_additions, ["Y"] = require("telescope-undo.actions").yank_deletions, ["u"] = require("telescope-undo.actions").restore, }, }, }, fzf = { fuzzy = true, override_generic_sorter = true, override_file_sorter = true, case_mode = "smart_case", }, }, }) -- Load extensions telescope.load_extension("fzf") telescope.load_extension("undo") telescope.load_extension("ui-select") -- Keymaps local function map(mode, lhs, rhs, desc) vim.keymap.set(mode, lhs, rhs, { desc = desc, noremap = true, silent = true }) end -- File navigation map("n", "ff", function() require("plugins.telescope.multigrep").live_multgrep() end, "Live multigrep") map("n", "p", smart_project_files, "Find project files") map("n", "fr", builtin.resume, "Resume last telescope") map("n", "fb", builtin.buffers, "Find buffers") map("n", "fo", builtin.oldfiles, "Find recent files") -- Search map("n", "gf", function() builtin.grep_string({ search = vim.fn.expand("") }) end, "Grep word under cursor") map("n", "gF", function() builtin.grep_string({ search = vim.fn.expand("") }) end, "Grep WORD under cursor") map("n", "gD", function() builtin.find_files({ search_file = vim.fn.expand("") }) end, "Find file with name under cursor") -- Git map("n", "gb", function() builtin.git_branches({ attach_mappings = function(_, map_func) map_func("i", "", actions.git_delete_branch) map_func("n", "", actions.git_delete_branch) return true end, }) end, "Git branches") map("n", "gc", builtin.git_commits, "Git commits") -- LSP map("n", "ds", builtin.lsp_document_symbols, "Document symbols") map("n", "ws", builtin.lsp_workspace_symbols, "Workspace symbols") map("n", "dws", builtin.lsp_dynamic_workspace_symbols, "Dynamic workspace symbols") -- Utilities map("n", "u", "Telescope undo", "Undo history") map("n", "ss", builtin.spell_suggest, "Spell suggestions") map("n", "m", builtin.marks, "Marks") map("n", "cc", builtin.commands, "Commands") map("n", "ch", builtin.command_history, "Command history") map("n", "vh", builtin.help_tags, "Help tags") -- Quickfix map("n", "ql", builtin.quickfix, "Quickfix list") map("n", "qhl", builtin.quickfixhistory, "Quickfix history") end, }