From 8ff9a0e4db298459941e35dc099264cceaed5eab Mon Sep 17 00:00:00 2001 From: Philipp Szechenyi Date: Thu, 10 Jul 2025 14:41:59 +0200 Subject: [PATCH 1/3] move telescope related lsp functions inside the telscope plugin declaration block --- init.lua | 63 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/init.lua b/init.lua index b98ffc61..377960e0 100644 --- a/init.lua +++ b/init.lua @@ -437,6 +437,44 @@ require('lazy').setup({ vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) + -- This runs on LSP attach per buffer (see main LSP attach function in 'neovim/nvim-lspconfig' config for more info, + -- it is better explained there). This is a little bit redundant, but we can switch off telescope for an optional + -- picker like snacks more easily when the keymaps are defined in the plugin itself. + -- It sets up buffer-local keymaps, autocommands, and other LSP-related settings + -- whenever an LSP client attaches to a buffer. + + 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. @@ -543,35 +581,10 @@ require('lazy').setup({ -- or a suggestion from your LSP for this to activate. map('gra', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' }) - -- Find references for the word under your cursor. - map('grr', require('telescope.builtin').lsp_references, '[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. - map('gri', require('telescope.builtin').lsp_implementations, '[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 . - map('grd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') - -- WARN: This is not Goto Definition, this is Goto Declaration. -- For example, in C this would take you to the header. map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') - -- Fuzzy find all the symbols in your current document. - -- Symbols are things like variables, functions, types, etc. - map('gO', require('telescope.builtin').lsp_document_symbols, 'Open Document Symbols') - - -- Fuzzy find all the symbols in your current workspace. - -- Similar to document symbols, except searches over your entire project. - map('gW', require('telescope.builtin').lsp_dynamic_workspace_symbols, '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*. - map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definition') - -- This function resolves a difference between neovim nightly (version 0.11) and stable (version 0.10) ---@param client vim.lsp.Client ---@param method vim.lsp.protocol.Method From 60c3c79d36e455215260e6a76637ba28d3b1c0e9 Mon Sep 17 00:00:00 2001 From: Philipp Szechenyi Date: Thu, 10 Jul 2025 15:28:55 +0200 Subject: [PATCH 2/3] explicitly enable telescope plugin, add some comments explainging why --- init.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/init.lua b/init.lua index 377960e0..87d850db 100644 --- a/init.lua +++ b/init.lua @@ -360,6 +360,15 @@ require('lazy').setup({ { -- Fuzzy Finder (files, lsp, etc) 'nvim-telescope/telescope.nvim', + -- To disable the default Telescope plugin and replace it with + -- another picker (like snacks), set enabled to false and + -- Enable your replacement picker by requiring it explicitly (e.g., 'kickstart.plugins.snacks') + -- By default, Telescope is included and acts as your picker for everything. + + -- Note: When you customize your config for yourself, + -- it’s best to remove the Telescope plugin config entirely + -- instead of just disabling it here, to keep your config clean. + enabled = true, event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim', From d2b64536e4eb7fc89458ea969816816bae3f463e Mon Sep 17 00:00:00 2001 From: Philipp Szechenyi Date: Thu, 10 Jul 2025 16:02:58 +0200 Subject: [PATCH 3/3] add snacks(picker) as an optional plugin add some comments to snacks picker to get it inline with telescope config --- init.lua | 1 + lua/kickstart/plugins/snacks.lua | 154 +++++++++++++++++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 lua/kickstart/plugins/snacks.lua diff --git a/init.lua b/init.lua index 87d850db..18d36df6 100644 --- a/init.lua +++ b/init.lua @@ -1001,6 +1001,7 @@ require('lazy').setup({ -- require 'kickstart.plugins.autopairs', -- require 'kickstart.plugins.neo-tree', -- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps + -- require 'kickstart.plugins.snacks', -- enable snacks picker -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` -- This is the easiest way to modularize your config. diff --git a/lua/kickstart/plugins/snacks.lua b/lua/kickstart/plugins/snacks.lua new file mode 100644 index 00000000..59e6502f --- /dev/null +++ b/lua/kickstart/plugins/snacks.lua @@ -0,0 +1,154 @@ +-- NOTE: Plugins can specify dependencies. +-- +-- The dependencies are proper plugin specifications as well - anything +-- you do for a plugin at the top level, you can do for a dependency. +-- +-- Use the `dependencies` key to specify the dependencies of a particular plugin + +return { -- Fuzzy Finder (files, lsp, etc) + 'folke/snacks.nvim', + priority = 1000, + lazy = false, + dependencies = { + -- Useful for getting pretty icons, but requires a Nerd Font. + { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, + }, + + -- snacks.nvim is a plugin that contains a collection of QoL improvements. + -- One of those plugins is called snacks-picker + -- It is a fuzzy finder, inspired by Telescope, that comes with a lot of different + -- things that it can fuzzy find! It's more than just a "file finder", it can search + -- many different aspects of Neovim, your workspace, LSP, and more! + -- + -- Two important keymaps to use while in a picker are: + -- - Insert mode: + -- - Normal mode: ? + -- + -- This opens a window that shows you all of the keymaps for the current + -- Snacks picker. This is really useful to discover what nacks-picker can + -- do as well as how to actually do it! + + -- [[ Configure Snacks Pickers ]] + -- See `:help snacks-picker` and `:help snacks-picker-setup` + ---@type snacks.Config + opts = { + picker = {}, + }, + + -- See `:help snacks-pickers-sources` + keys = { + { + 'sh', + function() + Snacks.picker.help() + end, + desc = '[S]earch [H]elp', + }, + { + 'sk', + function() + Snacks.picker.keymaps() + end, + desc = '[S]earch [K]eymaps', + }, + { + 'sf', + function() + Snacks.picker.smart() + end, + desc = '[S]earch [F]iles', + }, + { + 'ss', + function() + Snacks.picker.pickers() + end, + desc = '[S]earch [S]elect Snacks', + }, + { + 'sw', + function() + Snacks.picker.grep_word() + end, + desc = '[S]earch current [W]ord', + mode = { 'n', 'x' }, + }, + { + 'sg', + function() + Snacks.picker.grep() + end, + desc = '[S]earch by [G]rep', + }, + { + 'sd', + function() + Snacks.picker.diagnostics() + end, + desc = '[S]earch [D]iagnostics', + }, + { + 'sr', + function() + Snacks.picker.resume() + end, + desc = '[S]earch [R]esume', + }, + { + 's.', + function() + Snacks.picker.recent() + end, + desc = '[S]earch Recent Files ("." for repeat)', + }, + { + '', + function() + Snacks.picker.buffers() + end, + desc = '[ ] Find existing buffers', + }, + { + '/', + function() + Snacks.picker.lines {} + end, + desc = '[/] Fuzzily search in current buffer', + }, + { + 's/', + function() + Snacks.picker.grep_buffers() + end, + desc = '[S]earch [/] in Open Files', + }, + -- Shortcut for searching your Neovim configuration files + { + 'sn', + function() + Snacks.picker.files { cwd = vim.fn.stdpath 'config' } + end, + desc = '[S]earch [N]eovim files', + }, + }, + + -- This runs on LSP attach per buffer (see main LSP attach function in 'neovim/nvim-lspconfig' config for more info, + -- it is better explained there). This is a little bit redundant, but we can switch off pickers for an optional + -- picker like this one here more easily when the keymaps are defined in the plugin itself. + -- It sets up buffer-local keymaps, autocommands, and other LSP-related settings + -- whenever an LSP client attaches to a buffer. + config = function() + vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('snacks-lsp-attach', { clear = true }), + callback = function(event) + vim.keymap.set('n', 'grr', require('snacks').picker.lsp_references, { buffer = event.buf, desc = '[G]oto [R]eferences' }) + vim.keymap.set('n', 'gri', require('snacks').picker.lsp_implementations, { buffer = event.buf, desc = '[G]oto [I]mplementation' }) + vim.keymap.set('n', 'grd', require('snacks').picker.lsp_definitions, { buffer = event.buf, desc = '[G]oto [D]efinition' }) + vim.keymap.set('n', 'grD', vim.lsp.buf.declaration, { buffer = event.buf, desc = '[G]oto [D]eclaration' }) + vim.keymap.set('n', 'gO', require('snacks').picker.lsp_symbols, { buffer = event.buf, desc = 'Open Document Symbols' }) + vim.keymap.set('n', 'gW', require('snacks').picker.lsp_workspace_symbols, { buffer = event.buf, desc = 'Open Workspace Symbols' }) + vim.keymap.set('n', 'grt', require('snacks').picker.lsp_type_definitions, { buffer = event.buf, desc = '[G]oto [T]ype Definition' }) + end, + }) + end, +}