1
0
Fork 1
Dotfiles_nvim/lua/editor/snippets.lua

83 lines
2.8 KiB
Lua
Raw Normal View History

2024-09-07 23:50:39 +00:00
local K = require('core.keymap')
2024-07-02 21:52:43 +00:00
return {
{
'L3MON4D3/LuaSnip',
version = '2.*',
dependencies = {
'rafamadriz/friendly-snippets',
'mireq/luasnip-snippets',
},
build = 'make install_jsregexp',
config = function()
-- Setup --
require('luasnip.loaders.from_vscode').lazy_load()
require('luasnip.loaders.from_snipmate').lazy_load()
require('luasnip_snippets.common.snip_utils').setup()
end,
},
{
'hrsh7th/nvim-cmp',
dependencies = {
'L3MON4D3/LuaSnip',
'saadparwaiz1/cmp_luasnip',
'hrsh7th/cmp-nvim-lsp',
},
config = function()
-- Setup --
local cmp = require('cmp')
local luasnip = require('luasnip')
luasnip.setup({
load_ft_func = require('luasnip_snippets.common.snip_utils').load_ft_func,
ft_func = require('luasnip_snippets.common.snip_utils').ft_func,
enable_autosnippets = true,
})
-- Keybinding --
2024-09-07 23:50:39 +00:00
vim.keymap.set(
K.SNIPPETS.ACCEPT_OR_JUMP.mode,
K.SNIPPETS.ACCEPT_OR_JUMP.shortcut,
function()
if luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
vim.api.nvim_input('<C-V><Tab>') --Jump Placeholder of Snippets
end
end,
{ silent = true }
)
2024-07-02 21:52:43 +00:00
vim.keymap.set(
2024-09-07 23:50:39 +00:00
K.SNIPPETS.JUMP_BACKWARDS.mode,
K.SNIPPETS.JUMP_BACKWARDS.shortcut,
2024-07-02 21:52:43 +00:00
function() luasnip.jump(-1) end,
{ silent = true }
)
local doc_keybindings = {
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }),
}
-- Setup --
cmp.setup({
snippet = {
expand = function(args) luasnip.lsp_expand(args.body) end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert(doc_keybindings),
sources = cmp.config.sources({
{ name = 'lazydev', group_index = 0 },
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
}, { { name = 'buffer' } }),
})
end,
},
}