132 lines
5.8 KiB
Lua
132 lines
5.8 KiB
Lua
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 = {
|
|
['<c-w>'] = actions.add_selected_to_qflist + actions.open_qflist,
|
|
},
|
|
i = {
|
|
['<C-enter>'] = 'to_fuzzy_refine',
|
|
['<C-j>'] = actions.move_selection_next,
|
|
['<C-k>'] = actions.move_selection_previous,
|
|
['<C-space>'] = actions.add_selection,
|
|
['<C-h>'] = actions.add_selection,
|
|
['<C-l>'] = actions.select_default,
|
|
['<C-w>'] = actions.add_selected_to_qflist + actions.open_qflist,
|
|
['<C-c>'] = 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', '<leader>fh', builtin.help_tags, { desc = '[F]ind [H]elp' })
|
|
vim.keymap.set('n', '<leader>fk', builtin.keymaps, { desc = '[F]ind [K]eymaps' })
|
|
vim.keymap.set('n', '<leader>ff', builtin.find_files, { desc = '[F]ind [F]iles' })
|
|
vim.keymap.set('n', '<leader>fs', builtin.builtin, { desc = '[F]ind [S]elect Telescope' })
|
|
vim.keymap.set({ 'n', 'v' }, '<leader>fw', builtin.grep_string, { desc = '[F]ind current [W]ord' })
|
|
vim.keymap.set('n', '<leader>fg', builtin.live_grep, { desc = '[F]ind by [G]rep' })
|
|
vim.keymap.set('n', '<leader>fd', builtin.diagnostics, { desc = '[F]ind [D]iagnostics' })
|
|
vim.keymap.set('n', '<leader>f.', builtin.resume, { desc = '[F]ind [R]esume' })
|
|
vim.keymap.set('n', '<leader>fr', builtin.oldfiles, { desc = '[F]ind [R]ecent Files' })
|
|
vim.keymap.set('n', '<leader>fc', builtin.commands, { desc = '[F]ind [C]ommands' })
|
|
vim.keymap.set('n', '<leader>f<leader>', 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 <C-t>.
|
|
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', '<leader>/', 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', '<leader>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', '<leader>fn', function()
|
|
builtin.find_files { cwd = vim.fn.stdpath 'config' }
|
|
end, { desc = '[F]ind [N]eovim files' })
|
|
end
|