local actions = require("telescope.actions") local previewers = require("telescope.previewers") local builtin = require("telescope.builtin") local Job = require("plenary.job") local new_maker = function(filepath, bufnr, opts) filepath = vim.fn.expand(filepath) Job :new({ command = "file", args = { "--mime-type", "-b", filepath }, on_exit = function(j) local mime_type = vim.split(j:result()[1], "/")[1] if mime_type == "text" then previewers.buffer_previewer_maker(filepath, bufnr, opts) else vim.schedule(function() vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { "BINARY" }) end) end end, }) :sync() end require("telescope").setup({ defaults = { vimgrep_arguments = { "rg", "--color=never", "--no-heading", "--with-filename", "--line-number", "--column", "--smart-case", "--trim", }, sorting_strategy = "ascending", layout_config = { width = 0.75, prompt_position = "top", preview_cutoff = 120, }, pickers = { buffers = { mappings = { n = { ["d"] = actions.delete_buffer, }, }, sort_mru = true, preview_title = false, }, find_files = { find_command = { "fd", "-t f", "-c always", "-H", "--strip-cwd-prefix" }, hidden = true, }, file_browser = { hidden = true, }, lsp_references = { initial_mode = "normal", sorting_strategy = "ascending", layout_strategy = "cursor", preview_title = false, results_title = false, prompt_title = "References", layout_config = { width = 0.4, height = 0.4, }, }, lsp_code_actions = { initial_mode = "normal", sorting_strategy = "ascending", layout_strategy = "cursor", preview = false, prompt_title = "Code Actions", results_title = "", layout_config = { width = 0.2, height = 0.3, }, }, lsp_range_code_actions = { initial_mode = "normal", sorting_strategy = "ascending", layout_strategy = "cursor", preview = false, prompt_title = "Code Actions", results_title = "", layout_config = { width = 0.3, height = 0.3, }, }, lsp_document_diagnostics = { initial_mode = "normal", sorting_strategy = "ascending", layout_strategy = "cursor", prompt_title = "Diagnostics", results_title = "", layout_config = { width = 0.5, height = 0.5, }, }, lsp_definitions = { layout_strategy = "cursor", prompt_title = "Definitions", preview_title = false, results_title = false, layout_config = { width = 0.5, height = 0.5, }, }, }, selection_caret = "→", color_devicons = true, file_ignore_patterns = { "node_modules", ".git" }, set_env = { ["COLORTERM"] = "truecolor" }, buffer_previewer_maker = new_maker, mappings = { i = { [""] = actions.smart_send_to_qflist + actions.open_qflist, [""] = false, [""] = actions.select_horizontal, [""] = actions.select_default + actions.center, [""] = actions.close, [""] = actions.move_selection_next, [""] = actions.move_selection_previous, [""] = actions.toggle_selection + actions.move_selection_next, [""] = actions.send_selected_to_qflist, }, n = { [""] = actions.smart_send_to_qflist + actions.open_qflist, }, }, }, }) Project_files = function() local opts = {} local ok = pcall(require("telescope.builtin").git_files, opts) if not ok then require("telescope.builtin").find_files(opts) end end local delta = previewers.new_termopen_previewer({ get_command = function(entry) return { "git", "-c", "core.pager=delta", "-c", "delta.side-by-side=false", "diff", entry.value .. "^!" } end, }) Delta_git_commits = function(opts) opts = opts or {} opts.previewer = { delta, previewers.git_commit_message.new(opts), previewers.git_commit_diff_as_was.new(opts), } builtin.git_commits(opts) end Delta_git_bcommits = function(opts) opts = opts or {} opts.previewer = { delta, previewers.git_commit_message.new(opts), previewers.git_commit_diff_as_was.new(opts), } builtin.git_bcommits(opts) end local default_opts = { noremap = true, silent = true } vim.api.nvim_set_keymap("n", "", "Telescope help_tags", default_opts) vim.api.nvim_set_keymap("n", "", 'lua require("telescope").Project_files()', default_opts) vim.api.nvim_set_keymap("n", "", "Telescope file_browser hidden=true", default_opts) vim.api.nvim_set_keymap("n", "", "Telescope buffers", default_opts) vim.api.nvim_set_keymap("n", "", "Telescope live_grep", default_opts) vim.api.nvim_set_keymap("n", "", "Telescope git_commits", default_opts) vim.api.nvim_set_keymap("n", "", "Telescope resume", default_opts)