Skip to content

Commit 95a4fd6

Browse files
oriori1703SebastianBr11
authored andcommitted
Switch telescope for snacks.nvim
see nvim-lua#1481
1 parent ff5721e commit 95a4fd6

File tree

1 file changed

+102
-105
lines changed

1 file changed

+102
-105
lines changed

init.lua

Lines changed: 102 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -404,108 +404,105 @@ require('lazy').setup({
404404
-- Use the `dependencies` key to specify the dependencies of a particular plugin
405405

406406
{ -- Fuzzy Finder (files, lsp, etc)
407-
'nvim-telescope/telescope.nvim',
408-
event = 'VimEnter',
407+
'folke/snacks.nvim',
408+
priority = 1000,
409+
lazy = false,
409410
dependencies = {
410-
'nvim-lua/plenary.nvim',
411-
{ -- If encountering errors, see telescope-fzf-native README for installation instructions
412-
'nvim-telescope/telescope-fzf-native.nvim',
413-
414-
-- `build` is used to run some command when the plugin is installed/updated.
415-
-- This is only run then, not every time Neovim starts up.
416-
build = 'make',
417-
418-
-- `cond` is a condition used to determine whether this plugin should be
419-
-- installed and loaded.
420-
cond = function() return vim.fn.executable 'make' == 1 end,
421-
},
422-
{ 'nvim-telescope/telescope-ui-select.nvim' },
423-
424411
-- Useful for getting pretty icons, but requires a Nerd Font.
425412
{ 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font },
426413
},
427-
config = function()
428-
-- Telescope is a fuzzy finder that comes with a lot of different things that
429-
-- it can fuzzy find! It's more than just a "file finder", it can search
430-
-- many different aspects of Neovim, your workspace, LSP, and more!
431-
--
432-
-- The easiest way to use Telescope, is to start by doing something like:
433-
-- :Telescope help_tags
434-
--
435-
-- After running this command, a window will open up and you're able to
436-
-- type in the prompt window. You'll see a list of `help_tags` options and
437-
-- a corresponding preview of the help.
438-
--
439-
-- Two important keymaps to use while in Telescope are:
440-
-- - Insert mode: <c-/>
441-
-- - Normal mode: ?
442-
--
443-
-- This opens a window that shows you all of the keymaps for the current
444-
-- Telescope picker. This is really useful to discover what Telescope can
445-
-- do as well as how to actually do it!
446-
447-
-- [[ Configure Telescope ]]
448-
-- See `:help telescope` and `:help telescope.setup()`
449-
require('telescope').setup {
450-
-- You can put your default mappings / updates / etc. in here
451-
-- All the info you're looking for is in `:help telescope.setup()`
452-
--
453-
-- defaults = {
454-
-- mappings = {
455-
-- i = { ['<c-enter>'] = 'to_fuzzy_refine' },
456-
-- },
457-
-- },
458-
-- pickers = {}
459-
extensions = {
460-
['ui-select'] = {
461-
require('telescope.themes').get_dropdown(),
462-
},
463-
},
464-
}
465414

466-
-- Enable Telescope extensions if they are installed
467-
pcall(require('telescope').load_extension, 'fzf')
468-
pcall(require('telescope').load_extension, 'ui-select')
469-
470-
-- See `:help telescope.builtin`
471-
local builtin = require 'telescope.builtin'
472-
vim.keymap.set('n', '<leader>sh', builtin.help_tags, { desc = '[S]earch [H]elp' })
473-
vim.keymap.set('n', '<leader>sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' })
474-
vim.keymap.set('n', '<leader>sf', builtin.find_files, { desc = '[S]earch [F]iles' })
475-
vim.keymap.set('n', '<leader>ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' })
476-
vim.keymap.set({ 'n', 'v' }, '<leader>sw', builtin.grep_string, { desc = '[S]earch current [W]ord' })
477-
vim.keymap.set('n', '<leader>sg', builtin.live_grep, { desc = '[S]earch by [G]rep' })
478-
vim.keymap.set('n', '<leader>sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' })
479-
vim.keymap.set('n', '<leader>sr', builtin.resume, { desc = '[S]earch [R]esume' })
480-
vim.keymap.set('n', '<leader>s.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' })
481-
vim.keymap.set('n', '<leader><leader>', builtin.buffers, { desc = '[ ] Find existing buffers' })
482-
483-
-- Slightly advanced example of overriding default behavior and theme
484-
vim.keymap.set('n', '<leader>/', function()
485-
-- You can pass additional configuration to Telescope to change the theme, layout, etc.
486-
builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown {
487-
winblend = 10,
488-
previewer = false,
489-
})
490-
end, { desc = '[/] Fuzzily search in current buffer' })
491-
492-
-- It's also possible to pass additional configuration options.
493-
-- See `:help telescope.builtin.live_grep()` for information about particular keys
494-
vim.keymap.set(
495-
'n',
496-
'<leader>s/',
497-
function()
498-
builtin.live_grep {
499-
grep_open_files = true,
500-
prompt_title = 'Live Grep in Open Files',
501-
}
502-
end,
503-
{ desc = '[S]earch [/] in Open Files' }
504-
)
415+
-- snacks.nvim is a plugin that contains a collection of QoL improvements.
416+
-- One of those plugins is called snacks-picker
417+
-- It is a fuzzy finder, inspired by Telescope, that comes with a lot of different
418+
-- things that it can fuzzy find! It's more than just a "file finder", it can search
419+
-- many different aspects of Neovim, your workspace, LSP, and more!
420+
--
421+
-- Two important keymaps to use while in a picker are:
422+
-- - Insert mode: <c-/>
423+
-- - Normal mode: ?
424+
--
425+
-- This opens a window that shows you all of the keymaps for the current
426+
-- Snacks picker. This is really useful to discover what nacks-picker can
427+
-- do as well as how to actually do it!
505428

429+
-- [[ Configure Snacks Pickers ]]
430+
-- See `:help snacks-picker` and `:help snacks-picker-setup`
431+
---@type snacks.Config
432+
opts = {
433+
picker = {},
434+
},
435+
436+
-- See `:help snacks-pickers-sources`
437+
keys = {
438+
{
439+
'<leader>sh',
440+
function() Snacks.picker.help() end,
441+
desc = '[S]earch [H]elp',
442+
},
443+
{
444+
'<leader>sk',
445+
function() Snacks.picker.keymaps() end,
446+
desc = '[S]earch [K]eymaps',
447+
},
448+
{
449+
'<leader>sf',
450+
function() Snacks.picker.smart() end,
451+
desc = '[S]earch [F]iles',
452+
},
453+
{
454+
'<leader>ss',
455+
function() Snacks.picker.pickers() end,
456+
desc = '[S]earch [S]elect Snacks',
457+
},
458+
{
459+
'<leader>sw',
460+
function() Snacks.picker.grep_word() end,
461+
desc = '[S]earch current [W]ord',
462+
mode = { 'n', 'x' },
463+
},
464+
{
465+
'<leader>sg',
466+
function() Snacks.picker.grep() end,
467+
desc = '[S]earch by [G]rep',
468+
},
469+
{
470+
'<leader>sd',
471+
function() Snacks.picker.diagnostics() end,
472+
desc = '[S]earch [D]iagnostics',
473+
},
474+
{
475+
'<leader>sr',
476+
function() Snacks.picker.resume() end,
477+
desc = '[S]earch [R]esume',
478+
},
479+
{
480+
'<leader>s.',
481+
function() Snacks.picker.recent() end,
482+
desc = '[S]earch Recent Files ("." for repeat)',
483+
},
484+
{
485+
'<leader><leader>',
486+
function() Snacks.picker.buffers() end,
487+
desc = '[ ] Find existing buffers',
488+
},
489+
{
490+
'<leader>/',
491+
function() Snacks.picker.lines {} end,
492+
desc = '[/] Fuzzily search in current buffer',
493+
},
494+
{
495+
'<leader>s/',
496+
function() Snacks.picker.grep_buffers() end,
497+
desc = '[S]earch [/] in Open Files',
498+
},
506499
-- Shortcut for searching your Neovim configuration files
507-
vim.keymap.set('n', '<leader>sn', function() builtin.find_files { cwd = vim.fn.stdpath 'config' } end, { desc = '[S]earch [N]eovim files' })
508-
end,
500+
{
501+
'<leader>sn',
502+
function() Snacks.picker.files { cwd = vim.fn.stdpath 'config' } end,
503+
desc = '[S]earch [N]eovim files',
504+
},
505+
},
509506
},
510507

511508
-- LSP Plugins
@@ -521,6 +518,7 @@ require('lazy').setup({
521518
library = {
522519
-- Load luvit types when the `vim.uv` word is found
523520
{ path = '${3rd}/luv/library', words = { 'vim%.uv' } },
521+
{ path = 'snacks.nvim', words = { 'Snacks' } },
524522
},
525523
},
526524
},
@@ -599,33 +597,32 @@ require('lazy').setup({
599597
map('gra', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' })
600598

601599
-- Find references for the word under your cursor.
602-
map('grr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
603-
600+
map('grr', require('snacks').picker.lsp_references, '[G]oto [R]eferences')
604601
-- Jump to the implementation of the word under your cursor.
605602
-- Useful when your language has ways of declaring types without an actual implementation.
606-
map('gri', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
603+
map('gri', require('snacks').picker.lsp_implementations, '[G]oto [I]mplementation')
607604

608605
-- Jump to the definition of the word under your cursor.
609606
-- This is where a variable was first declared, or where a function is defined, etc.
610607
-- To jump back, press <C-t>.
611-
map('grd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
608+
map('grd', require('snacks').picker.lsp_definitions, '[G]oto [D]efinition')
612609

613610
-- WARN: This is not Goto Definition, this is Goto Declaration.
614611
-- For example, in C this would take you to the header.
615612
map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
616613

617614
-- Fuzzy find all the symbols in your current document.
618615
-- Symbols are things like variables, functions, types, etc.
619-
map('gO', require('telescope.builtin').lsp_document_symbols, 'Open Document Symbols')
616+
map('gO', require('snacks').picker.lsp_symbols, 'Open Document Symbols')
620617

621618
-- Fuzzy find all the symbols in your current workspace.
622619
-- Similar to document symbols, except searches over your entire project.
623-
map('gW', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Open Workspace Symbols')
620+
map('gW', require('snacks').picker.lsp_workspace_symbols, 'Open Workspace Symbols')
624621

625622
-- Jump to the type of the word under your cursor.
626623
-- Useful when you're not sure what type a variable is and you want to see
627624
-- the definition of its *type*, not where it was *defined*.
628-
map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definition')
625+
map('grt', require('snacks').picker.lsp_type_definitions, '[G]oto [T]ype Definition')
629626

630627
-- Toggle to show/hide diagnostic messages
631628
map('<leader>td', function() vim.diagnostic.enable(not vim.diagnostic.is_enabled()) end, '[T]oggle [D]iagnostics')
@@ -1129,7 +1126,7 @@ require('lazy').setup({
11291126
-- Change the name of the colorscheme plugin below, and then
11301127
-- change the command in the config to whatever the name of that colorscheme is.
11311128
--
1132-
-- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`.
1129+
-- If you want to see what colorschemes are already installed, you can use `:lua Snacks.picker.colorschemes()`.
11331130
'folke/tokyonight.nvim',
11341131
priority = 1000, -- Make sure to load this before all the other start plugins.
11351132
config = function()
@@ -1246,9 +1243,9 @@ require('lazy').setup({
12461243
{ import = 'custom.plugins' },
12471244
--
12481245
-- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec`
1249-
-- Or use telescope!
1246+
-- Or use the "help" snacks-picker!
12501247
-- In normal mode type `<space>sh` then write `lazy.nvim-plugin`
1251-
-- you can continue same window with `<space>sr` which resumes last telescope search
1248+
-- you can continue same window with `<space>sr` which resumes last snacks-picker search
12521249
}, { ---@diagnostic disable-line: missing-fields
12531250
ui = {
12541251
-- If you are using a Nerd Font: set icons to an empty table which will use the

0 commit comments

Comments
 (0)