repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
neovim/lua/patches/snippet.lua
RawFile outline
--- source https://boltlessengineer.github.io/posts/neovim-config-without-plugins/
---
---@param trigger string trigger string for snippet
---@param body string snippet text that will be expanded
---@param opts? vim.keymap.set.Opts
---
---Refer to <https://microsoft.github.io/language-server-protocol/specification/#snippet_syntax>
---for the specification of valid body.
function vim.snippet.add( trigger, body, opts )
vim.keymap.set( 'ia', trigger, function ()
-- If abbrev is expanded with keys like "(", ")", "<cr>", "<space>",
-- don't expand the snippet. Only accept "<c-]>" as trigger key.
local c = vim.fn.nr2char( vim.fn.getchar( 0 ) )
if c ~= '' then
vim.api.nvim_feedkeys( trigger .. c, 'i', true )
return
end
vim.snippet.expand( body )
end, opts )
end