-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Optional snacks #1632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
szechp
wants to merge
1
commit into
nvim-lua:master
Choose a base branch
from
szechp:optional-snacks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+155
−0
Open
Optional snacks #1632
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: <c-/> | ||
-- - 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 = { | ||
{ | ||
'<leader>sh', | ||
function() | ||
Snacks.picker.help() | ||
end, | ||
desc = '[S]earch [H]elp', | ||
}, | ||
{ | ||
'<leader>sk', | ||
function() | ||
Snacks.picker.keymaps() | ||
end, | ||
desc = '[S]earch [K]eymaps', | ||
}, | ||
{ | ||
'<leader>sf', | ||
function() | ||
Snacks.picker.smart() | ||
end, | ||
desc = '[S]earch [F]iles', | ||
}, | ||
{ | ||
'<leader>ss', | ||
function() | ||
Snacks.picker.pickers() | ||
end, | ||
desc = '[S]earch [S]elect Snacks', | ||
}, | ||
{ | ||
'<leader>sw', | ||
function() | ||
Snacks.picker.grep_word() | ||
end, | ||
desc = '[S]earch current [W]ord', | ||
mode = { 'n', 'x' }, | ||
}, | ||
{ | ||
'<leader>sg', | ||
function() | ||
Snacks.picker.grep() | ||
end, | ||
desc = '[S]earch by [G]rep', | ||
}, | ||
{ | ||
'<leader>sd', | ||
function() | ||
Snacks.picker.diagnostics() | ||
end, | ||
desc = '[S]earch [D]iagnostics', | ||
}, | ||
{ | ||
'<leader>sr', | ||
function() | ||
Snacks.picker.resume() | ||
end, | ||
desc = '[S]earch [R]esume', | ||
}, | ||
{ | ||
'<leader>s.', | ||
function() | ||
Snacks.picker.recent() | ||
end, | ||
desc = '[S]earch Recent Files ("." for repeat)', | ||
}, | ||
{ | ||
'<leader><leader>', | ||
function() | ||
Snacks.picker.buffers() | ||
end, | ||
desc = '[ ] Find existing buffers', | ||
}, | ||
{ | ||
'<leader>/', | ||
function() | ||
Snacks.picker.lines {} | ||
end, | ||
desc = '[/] Fuzzily search in current buffer', | ||
}, | ||
{ | ||
'<leader>s/', | ||
function() | ||
Snacks.picker.grep_buffers() | ||
end, | ||
desc = '[S]earch [/] in Open Files', | ||
}, | ||
-- Shortcut for searching your Neovim configuration files | ||
{ | ||
'<leader>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, | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a question, should this not be
init
instead ofconfig
?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This used to be together with this:
#1640
I separated them into two prs. This one will likely not be merged, at least according to what I feel is the current consensus regarding kickstart.
If you ever want to replace telescope, you can always take this once the smaller change is merged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @szechp, i did replace telescope with snacks, but it looks like using
config
as is will override anyopts
being set.. only thing that worked for me was to replace it withinit