|
| 1 | +-- NOTE: Plugins can specify dependencies. |
| 2 | +-- |
| 3 | +-- The dependencies are proper plugin specifications as well - anything |
| 4 | +-- you do for a plugin at the top level, you can do for a dependency. |
| 5 | +-- |
| 6 | +-- Use the `dependencies` key to specify the dependencies of a particular plugin |
| 7 | + |
| 8 | +return { -- Fuzzy Finder (files, lsp, etc) |
| 9 | + 'folke/snacks.nvim', |
| 10 | + priority = 1000, |
| 11 | + lazy = false, |
| 12 | + dependencies = { |
| 13 | + -- Useful for getting pretty icons, but requires a Nerd Font. |
| 14 | + { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, |
| 15 | + }, |
| 16 | + |
| 17 | + -- snacks.nvim is a plugin that contains a collection of QoL improvements. |
| 18 | + -- One of those plugins is called snacks-picker |
| 19 | + -- It is a fuzzy finder, inspired by Telescope, that comes with a lot of different |
| 20 | + -- things that it can fuzzy find! It's more than just a "file finder", it can search |
| 21 | + -- many different aspects of Neovim, your workspace, LSP, and more! |
| 22 | + -- |
| 23 | + -- Two important keymaps to use while in a picker are: |
| 24 | + -- - Insert mode: <c-/> |
| 25 | + -- - Normal mode: ? |
| 26 | + -- |
| 27 | + -- This opens a window that shows you all of the keymaps for the current |
| 28 | + -- Snacks picker. This is really useful to discover what nacks-picker can |
| 29 | + -- do as well as how to actually do it! |
| 30 | + |
| 31 | + -- [[ Configure Snacks Pickers ]] |
| 32 | + -- See `:help snacks-picker` and `:help snacks-picker-setup` |
| 33 | + ---@type snacks.Config |
| 34 | + opts = { |
| 35 | + picker = {}, |
| 36 | + }, |
| 37 | + |
| 38 | + -- See `:help snacks-pickers-sources` |
| 39 | + keys = { |
| 40 | + { |
| 41 | + '<leader>sh', |
| 42 | + function() |
| 43 | + Snacks.picker.help() |
| 44 | + end, |
| 45 | + desc = '[S]earch [H]elp', |
| 46 | + }, |
| 47 | + { |
| 48 | + '<leader>sk', |
| 49 | + function() |
| 50 | + Snacks.picker.keymaps() |
| 51 | + end, |
| 52 | + desc = '[S]earch [K]eymaps', |
| 53 | + }, |
| 54 | + { |
| 55 | + '<leader>sf', |
| 56 | + function() |
| 57 | + Snacks.picker.smart() |
| 58 | + end, |
| 59 | + desc = '[S]earch [F]iles', |
| 60 | + }, |
| 61 | + { |
| 62 | + '<leader>ss', |
| 63 | + function() |
| 64 | + Snacks.picker.pickers() |
| 65 | + end, |
| 66 | + desc = '[S]earch [S]elect Snacks', |
| 67 | + }, |
| 68 | + { |
| 69 | + '<leader>sw', |
| 70 | + function() |
| 71 | + Snacks.picker.grep_word() |
| 72 | + end, |
| 73 | + desc = '[S]earch current [W]ord', |
| 74 | + mode = { 'n', 'x' }, |
| 75 | + }, |
| 76 | + { |
| 77 | + '<leader>sg', |
| 78 | + function() |
| 79 | + Snacks.picker.grep() |
| 80 | + end, |
| 81 | + desc = '[S]earch by [G]rep', |
| 82 | + }, |
| 83 | + { |
| 84 | + '<leader>sd', |
| 85 | + function() |
| 86 | + Snacks.picker.diagnostics() |
| 87 | + end, |
| 88 | + desc = '[S]earch [D]iagnostics', |
| 89 | + }, |
| 90 | + { |
| 91 | + '<leader>sr', |
| 92 | + function() |
| 93 | + Snacks.picker.resume() |
| 94 | + end, |
| 95 | + desc = '[S]earch [R]esume', |
| 96 | + }, |
| 97 | + { |
| 98 | + '<leader>s.', |
| 99 | + function() |
| 100 | + Snacks.picker.recent() |
| 101 | + end, |
| 102 | + desc = '[S]earch Recent Files ("." for repeat)', |
| 103 | + }, |
| 104 | + { |
| 105 | + '<leader><leader>', |
| 106 | + function() |
| 107 | + Snacks.picker.buffers() |
| 108 | + end, |
| 109 | + desc = '[ ] Find existing buffers', |
| 110 | + }, |
| 111 | + { |
| 112 | + '<leader>/', |
| 113 | + function() |
| 114 | + Snacks.picker.lines {} |
| 115 | + end, |
| 116 | + desc = '[/] Fuzzily search in current buffer', |
| 117 | + }, |
| 118 | + { |
| 119 | + '<leader>s/', |
| 120 | + function() |
| 121 | + Snacks.picker.grep_buffers() |
| 122 | + end, |
| 123 | + desc = '[S]earch [/] in Open Files', |
| 124 | + }, |
| 125 | + -- Shortcut for searching your Neovim configuration files |
| 126 | + { |
| 127 | + '<leader>sn', |
| 128 | + function() |
| 129 | + Snacks.picker.files { cwd = vim.fn.stdpath 'config' } |
| 130 | + end, |
| 131 | + desc = '[S]earch [N]eovim files', |
| 132 | + }, |
| 133 | + }, |
| 134 | + |
| 135 | + -- This runs on LSP attach per buffer (see main LSP attach function in 'neovim/nvim-lspconfig' config for more info, |
| 136 | + -- it is better explained there). This is a little bit redundant, but we can switch off pickers for an optional |
| 137 | + -- picker like this one here more easily when the keymaps are defined in the plugin itself. |
| 138 | + -- It sets up buffer-local keymaps, autocommands, and other LSP-related settings |
| 139 | + -- whenever an LSP client attaches to a buffer. |
| 140 | + config = function() |
| 141 | + vim.api.nvim_create_autocmd('LspAttach', { |
| 142 | + group = vim.api.nvim_create_augroup('snacks-lsp-attach', { clear = true }), |
| 143 | + callback = function(event) |
| 144 | + vim.keymap.set('n', 'grr', require('snacks').picker.lsp_references, { buffer = event.buf, desc = '[G]oto [R]eferences' }) |
| 145 | + vim.keymap.set('n', 'gri', require('snacks').picker.lsp_implementations, { buffer = event.buf, desc = '[G]oto [I]mplementation' }) |
| 146 | + vim.keymap.set('n', 'grd', require('snacks').picker.lsp_definitions, { buffer = event.buf, desc = '[G]oto [D]efinition' }) |
| 147 | + vim.keymap.set('n', 'grD', vim.lsp.buf.declaration, { buffer = event.buf, desc = '[G]oto [D]eclaration' }) |
| 148 | + vim.keymap.set('n', 'gO', require('snacks').picker.lsp_symbols, { buffer = event.buf, desc = 'Open Document Symbols' }) |
| 149 | + vim.keymap.set('n', 'gW', require('snacks').picker.lsp_workspace_symbols, { buffer = event.buf, desc = 'Open Workspace Symbols' }) |
| 150 | + vim.keymap.set('n', 'grt', require('snacks').picker.lsp_type_definitions, { buffer = event.buf, desc = '[G]oto [T]ype Definition' }) |
| 151 | + end, |
| 152 | + }) |
| 153 | + end, |
| 154 | +} |
0 commit comments