|
| 1 | +vim.pack.add { 'https://github.com/folke/snacks.nvim' } |
| 2 | + |
| 3 | +require('snacks').setup { |
| 4 | + picker = {}, |
| 5 | + lazygit = {}, |
| 6 | + image = { doc = { inline = false } }, |
| 7 | + indent = { |
| 8 | + scope = { |
| 9 | + underline = true, |
| 10 | + char = '▎', |
| 11 | + }, |
| 12 | + animate = { enabled = false }, |
| 13 | + }, |
| 14 | +} |
| 15 | + |
| 16 | +vim.keymap.set('n', '<leader>sh', function() Snacks.picker.help() end, { desc = '[S]earch [H]elp' }) |
| 17 | +vim.keymap.set('n', '<leader>sk', function() Snacks.picker.keymaps() end, { desc = '[S]earch [K]eymaps' }) |
| 18 | +vim.keymap.set('n', '<leader>sf', function() Snacks.picker.smart() end, { desc = '[S]earch [F]iles' }) |
| 19 | +vim.keymap.set('n', '<leader>ss', function() Snacks.picker.pickers() end, { desc = '[S]earch [S]elect Snacks' }) |
| 20 | +vim.keymap.set({ 'n', 'x' }, '<leader>sw', function() Snacks.picker.grep_word() end, { desc = '[S]earch current [W]ord' }) |
| 21 | +vim.keymap.set('n', '<leader>sg', function() Snacks.picker.grep() end, { desc = '[S]earch by [G]rep' }) |
| 22 | +vim.keymap.set('n', '<leader>sd', function() Snacks.picker.diagnostics() end, { desc = '[S]earch [D]iagnostics' }) |
| 23 | +vim.keymap.set('n', '<leader>sr', function() Snacks.picker.resume() end, { desc = '[S]earch [R]esume' }) |
| 24 | +vim.keymap.set('n', '<leader>s.', function() Snacks.picker.recent() end, { desc = '[S]earch Recent Files ("." for repeat)' }) |
| 25 | +vim.keymap.set('n', '<leader><leader>', function() Snacks.picker.buffers() end, { desc = '[ ] Find existing buffers' }) |
| 26 | +vim.keymap.set('n', '<leader>/', function() Snacks.picker.lines {} end, { desc = '[/] Fuzzily search in current buffer' }) |
| 27 | +-- Shortcut for searching your Neovim configuration files |
| 28 | +vim.keymap.set('n', '<leader>sn', function() Snacks.picker.files { cwd = vim.fn.stdpath 'config' } end, { desc = '[S]earch [N]eovim files' }) |
| 29 | + |
| 30 | +-- Non kickstart telescope pickers: |
| 31 | +vim.keymap.set('n', '<leader>sp', function() Snacks.picker.projects { dev = { '~/Projects/' } } end, { desc = '[S]earch [P]rojects' }) |
| 32 | +vim.keymap.set('n', '<leader>sM', function() Snacks.picker.man() end, { desc = '[S]earch [M]an pages' }) |
| 33 | +vim.keymap.set('n', '<leader>hl', function() Snacks.lazygit() end, { desc = '[H]hunk [L]azygit' }) |
| 34 | + |
| 35 | +-- This runs on LSP attach per buffer (see main LSP attach function in 'neovim/nvim-lspconfig' config for more info, |
| 36 | +-- it is better explained there). This allows easily switching between pickers if you prefer using something else! |
| 37 | +vim.api.nvim_create_autocmd('LspAttach', { |
| 38 | + group = vim.api.nvim_create_augroup('snacks-lsp-attach', { clear = true }), |
| 39 | + callback = function(event) |
| 40 | + local buf = event.buf |
| 41 | + |
| 42 | + -- Find references for the word under your cursor. |
| 43 | + vim.keymap.set('n', 'grr', Snacks.picker.lsp_references, { buffer = buf, desc = '[G]oto [R]eferences' }) |
| 44 | + |
| 45 | + -- Jump to the implementation of the word under your cursor. |
| 46 | + -- Useful when your language has ways of declaring types without an actual implementation. |
| 47 | + vim.keymap.set('n', 'gri', Snacks.picker.lsp_implementations, { buffer = buf, desc = '[G]oto [I]mplementation' }) |
| 48 | + |
| 49 | + -- Jump to the definition of the word under your cursor. |
| 50 | + -- This is where a variable was first declared, or where a function is defined, etc. |
| 51 | + -- To jump back, press <C-t>. |
| 52 | + vim.keymap.set('n', 'grd', Snacks.picker.lsp_definitions, { buffer = buf, desc = '[G]oto [D]efinition' }) |
| 53 | + |
| 54 | + -- Fuzzy find all the symbols in your current document. |
| 55 | + -- Symbols are things like variables, functions, types, etc. |
| 56 | + vim.keymap.set('n', 'gO', Snacks.picker.lsp_symbols, { buffer = buf, desc = 'Open Document Symbols' }) |
| 57 | + |
| 58 | + -- Fuzzy find all the symbols in your current workspace. |
| 59 | + -- Similar to document symbols, except searches over your entire project. |
| 60 | + vim.keymap.set('n', 'gW', Snacks.picker.lsp_workspace_symbols, { buffer = buf, desc = 'Open Workspace Symbols' }) |
| 61 | + |
| 62 | + -- Jump to the type of the word under your cursor. |
| 63 | + -- Useful when you're not sure what type a variable is and you want to see |
| 64 | + -- the definition of its *type*, not where it was *defined*. |
| 65 | + vim.keymap.set('n', 'grt', Snacks.picker.lsp_type_definitions, { buffer = buf, desc = '[G]oto [T]ype Definition' }) |
| 66 | + end, |
| 67 | +}) |
| 68 | + |
| 69 | +-- vim: ts=2 sts=2 sw=2 et |
0 commit comments