local function gh(repo) return 'https://github.com/' .. repo end do ---@type (string|vim.pack.Spec)[] local telescope_plugins = { gh 'nvim-lua/plenary.nvim', gh 'nvim-telescope/telescope.nvim', gh 'nvim-telescope/telescope-ui-select.nvim', } if vim.fn.executable 'make' == 1 then table.insert(telescope_plugins, gh 'nvim-telescope/telescope-fzf-native.nvim') end -- NOTE: You can install multiple plugins at once vim.pack.add(telescope_plugins) local actions = require 'telescope.actions' -- [[ Configure Telescope ]] -- See `:help telescope` and `:help telescope.setup()` require('telescope').setup { -- You can put your default mappings / updates / etc. in here -- All the info you're looking for is in `:help telescope.setup()` defaults = { layout_strategy = 'horizontal', layout_config = { width = 0.9, height = 0.9, }, preview_width = 0.6, path_display = { 'truncate' }, mappings = { n = { [''] = actions.add_selected_to_qflist + actions.open_qflist, }, i = { [''] = 'to_fuzzy_refine', [''] = actions.move_selection_next, [''] = actions.move_selection_previous, [''] = actions.add_selection, [''] = actions.add_selection, [''] = actions.select_default, [''] = actions.add_selected_to_qflist + actions.open_qflist, [''] = actions.close, }, }, }, pickers = { find_files = { find_command = { 'rg', '--files', '--hidden', '--glob', '!**/.git/*' }, }, }, extensions = { ['ui-select'] = { require('telescope.themes').get_dropdown(), }, }, } -- Enable Telescope extensions if they are installed pcall(require('telescope').load_extension, 'fzf') pcall(require('telescope').load_extension, 'ui-select') -- See `:help telescope.builtin` local builtin = require 'telescope.builtin' vim.keymap.set('n', 'fh', builtin.help_tags, { desc = '[F]ind [H]elp' }) vim.keymap.set('n', 'fk', builtin.keymaps, { desc = '[F]ind [K]eymaps' }) vim.keymap.set('n', 'ff', builtin.find_files, { desc = '[F]ind [F]iles' }) vim.keymap.set('n', 'fs', builtin.builtin, { desc = '[F]ind [S]elect Telescope' }) vim.keymap.set({ 'n', 'v' }, 'fw', builtin.grep_string, { desc = '[F]ind current [W]ord' }) vim.keymap.set('n', 'fg', builtin.live_grep, { desc = '[F]ind by [G]rep' }) vim.keymap.set('n', 'fd', builtin.diagnostics, { desc = '[F]ind [D]iagnostics' }) vim.keymap.set('n', 'f.', builtin.resume, { desc = '[F]ind [R]esume' }) vim.keymap.set('n', 'fr', builtin.oldfiles, { desc = '[F]ind [R]ecent Files' }) vim.keymap.set('n', 'fc', builtin.commands, { desc = '[F]ind [C]ommands' }) vim.keymap.set('n', 'f', builtin.buffers, { desc = '[F]ind existing buffers' }) -- Add Telescope-based LSP pickers when an LSP attaches to a buffer. -- If you later switch picker plugins, this is where to update these mappings. vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('telescope-lsp-attach', { clear = true }), callback = function(event) local buf = event.buf -- Find references for the word under your cursor. vim.keymap.set('n', 'grr', builtin.lsp_references, { buffer = buf, desc = '[G]oto [R]eferences' }) -- Jump to the implementation of the word under your cursor. -- Useful when your language has ways of declaring types without an actual implementation. vim.keymap.set('n', 'gri', builtin.lsp_implementations, { buffer = buf, desc = '[G]oto [I]mplementation' }) -- Jump to the definition of the word under your cursor. -- This is where a variable was first declared, or where a function is defined, etc. -- To jump back, press . vim.keymap.set('n', 'grd', builtin.lsp_definitions, { buffer = buf, desc = '[G]oto [D]efinition' }) -- Fuzzy find all the symbols in your current document. -- Symbols are things like variables, functions, types, etc. vim.keymap.set('n', 'gO', builtin.lsp_document_symbols, { buffer = buf, desc = 'Open Document Symbols' }) -- Fuzzy find all the symbols in your current workspace. -- Similar to document symbols, except searches over your entire project. vim.keymap.set('n', 'gW', builtin.lsp_dynamic_workspace_symbols, { buffer = buf, desc = 'Open Workspace Symbols' }) -- Jump to the type of the word under your cursor. -- Useful when you're not sure what type a variable is and you want to see -- the definition of its *type*, not where it was *defined*. vim.keymap.set('n', 'grt', builtin.lsp_type_definitions, { buffer = buf, desc = '[G]oto [T]ype Definition' }) end, }) -- Slightly advanced example of overriding default behavior and theme vim.keymap.set('n', '/', function() -- You can pass additional configuration to Telescope to change the theme, layout, etc. builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { winblend = 10, previewer = true, }) end, { desc = '[/] Fuzzily search in current buffer' }) -- It's also possible to pass additional configuration options. -- See `:help telescope.builtin.live_grep()` for information about particular keys vim.keymap.set( 'n', 'f/', function() builtin.live_grep { grep_open_files = true, prompt_title = 'Live Grep in Open Files', } end, { desc = '[F]ind [/] in Open Files' } ) -- Shortcut for searching your Neovim configuration files vim.keymap.set('n', 'fn', function() builtin.find_files { cwd = vim.fn.stdpath 'config' } end, { desc = '[F]ind [N]eovim files' }) end