From d6cfaf09817945353f122da6ee5da9fb7b64f046 Mon Sep 17 00:00:00 2001 From: Philipp Szechenyi Date: Tue, 10 Jun 2025 22:25:27 +0200 Subject: [PATCH] add snacks as an optional replacement for telescope --- lua/kickstart/plugins/lspconfig.lua | 7 ++ lua/kickstart/plugins/snacks.lua | 135 +++++++++++++++++++++++++++ lua/kickstart/plugins/tokyonight.lua | 2 +- lua/lazy-plugins.lua | 4 +- 4 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 lua/kickstart/plugins/snacks.lua diff --git a/lua/kickstart/plugins/lspconfig.lua b/lua/kickstart/plugins/lspconfig.lua index 6532757d872..919210e1e16 100644 --- a/lua/kickstart/plugins/lspconfig.lua +++ b/lua/kickstart/plugins/lspconfig.lua @@ -82,15 +82,19 @@ return { -- Find references for the word under your cursor. map('grr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') + -- if you want to use the snacks picker instead, you need to uncomment the lines below the keymaps, and remove the ones referencing telescope. + -- map('grr', require('snacks').picker.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') + -- map('gri', require('snacks').picker.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') + -- map('grd', require('snacks').picker.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. @@ -99,15 +103,18 @@ return { -- 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') + -- map('gO', require('snacks').picker.lsp_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') + -- map('gW', require('snacks').picker.lsp_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') + -- map('grt', require('snacks').picker.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 diff --git a/lua/kickstart/plugins/snacks.lua b/lua/kickstart/plugins/snacks.lua new file mode 100644 index 00000000000..617b9755b02 --- /dev/null +++ b/lua/kickstart/plugins/snacks.lua @@ -0,0 +1,135 @@ +-- 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', + }, + }, + } +-- vim: ts=2 sts=2 sw=2 et diff --git a/lua/kickstart/plugins/tokyonight.lua b/lua/kickstart/plugins/tokyonight.lua index 1b32f79114b..44b56ea1576 100644 --- a/lua/kickstart/plugins/tokyonight.lua +++ b/lua/kickstart/plugins/tokyonight.lua @@ -3,7 +3,7 @@ return { -- Change the name of the colorscheme plugin below, and then -- change the command in the config to whatever the name of that colorscheme is. -- - -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`. + -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme` or `:lua Snacks.picker.colorschemes()` depening on what picker you use. 'folke/tokyonight.nvim', priority = 1000, -- Make sure to load this before all the other start plugins. config = function() diff --git a/lua/lazy-plugins.lua b/lua/lazy-plugins.lua index 0a2b211af69..f956ab5ee51 100644 --- a/lua/lazy-plugins.lua +++ b/lua/lazy-plugins.lua @@ -65,9 +65,9 @@ require('lazy').setup({ -- { import = 'custom.plugins' }, -- -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec` - -- Or use telescope! + -- Or use telescope or the "help" snacks-picker, depending on which one you use! -- In normal mode type `sh` then write `lazy.nvim-plugin` - -- you can continue same window with `sr` which resumes last telescope search + -- you can continue same window with `sr` which resumes last telescope or snacks-picker search }, { ui = { -- If you are using a Nerd Font: set icons to an empty table which will use the