return { "nvim-telescope/telescope.nvim", dependencies = { "nvim-lua/plenary.nvim", { "nvim-telescope/telescope-fzf-native.nvim", build = "make" }, "nvim-tree/nvim-web-devicons", "debugloop/telescope-undo.nvim", "nvim-telescope/telescope-ui-select.nvim", }, config = function() local telescope = require("telescope") local actions = require("telescope.actions") local previewers = require("telescope.previewers") local previewers_utils = require("telescope.previewers.utils") local sorters = require("telescope.sorters") local builtin = require("telescope.builtin") local max_size = 100000 local truncate_large_files = function(filepath, bufnr, opts) opts = opts or {} filepath = vim.fn.expand(filepath) ---@diagnostic disable-next-line: undefined-field vim.loop.fs_stat(filepath, function(_, stat) if not stat then return end if stat.size > max_size then local cmd = { "head", "-c", max_size, filepath } previewers_utils.job_maker(cmd, bufnr, opts) else previewers.buffer_previewer_maker(filepath, bufnr, opts) end end) end telescope.setup({ defaults = vim.tbl_extend( "force", require("telescope.themes").get_ivy(), { file_sorter = 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" }, 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, }, }, } ), pickers = { diagnostics = { initial_mode = "normal", layout_config = { preview_cutoff = 9999, }, }, }, themes = { ivy = { layout_strategy = 'bottom_pane', layout_config = { height = 50, }, }, }, extensions = { undo = { side_by_side = true, 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, }, }, }, }, }) telescope.load_extension("fzf") telescope.load_extension("undo") telescope.load_extension("ui-select") -- We cache the results of "git rev-parse" -- Process creation is expensive in Windows, so this reduces latency local is_inside_work_tree = {} local project_files = function() 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 if is_inside_work_tree[cwd] then builtin.git_files({ show_untracked = true, hidden = true }) else builtin.find_files({}) end end -- set keymaps local keymap = vim.keymap keymap.set("n", "ff", function() require("plugins.telescope.multigrep").live_multgrep() end, {}) keymap.set("n", "p", project_files, {}) keymap.set("n", "fr", builtin.resume, {}) keymap.set("n", "fb", builtin.buffers, {}) keymap.set("n", "fo", builtin.oldfiles, {}) keymap.set("n", "m", builtin.marks, {}) keymap.set("n", "cc", builtin.commands, {}) keymap.set("n", "ch", builtin.command_history, {}) keymap.set("n", "gb", function() builtin.git_branches({ attach_mappings = function(_, map) map("i", "", actions.git_delete_branch) map("n", "", actions.git_delete_branch) return true end, }) end, {}) keymap.set("n", "gc", builtin.git_commits, {}) keymap.set("n", "vh", builtin.help_tags, {}) keymap.set("n", "ds", builtin.lsp_document_symbols, {}) keymap.set("n", "ws", builtin.lsp_workspace_symbols, {}) keymap.set("n", "dws", builtin.lsp_dynamic_workspace_symbols, {}) keymap.set("n", "gf", function() builtin.grep_string({ search = vim.fn.expand(""), }) end) keymap.set("n", "gF", function() builtin.grep_string({ search = vim.fn.expand(""), }) end) keymap.set("n", "gD", function() builtin.find_files({ search_file = vim.fn.expand(""), }) end) vim.keymap.set("n", "u", "Telescope undo") end, }