snippet
基本配置
以下是我的 LuaSnip 插件配置,包含了基本功能的设定和与 nvim-cmp
的集成。
lua
├── plugins
│ ├── init.lua
│ └── lang-core
│ └── snippet.lua # 配置 snippet 引擎
└── snippets
└── lua_snippets # lua 配置的 snippets
├── lua.lua
└── python.lua
lang-core/snippet.lua
lang-core/snippet.lua
return {
{
"L3MON4D3/LuaSnip",
build = (not jit.os:find("Windows"))
and "echo 'NOTE: jsregexp is optional, so not a big deal if it fails to build'; make install_jsregexp"
or nil,
dependencies = {
{
"rafamadriz/friendly-snippets",
config = function()
require("luasnip.loaders.from_vscode").lazy_load()
end,
},
{
"nvim-cmp",
dependencies = {
"saadparwaiz1/cmp_luasnip",
},
opts = function(_, opts)
opts.snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
}
table.insert(opts.sources, { name = "luasnip" })
end,
},
},
opts = function(_, opts)
local ls = require("luasnip")
local types = require("luasnip.util.types")
ls.setup({
keep_roots = true,
link_roots = true,
link_children = true,
update_events = "TextChanged,TextChangedI",
delete_check_events = "TextChanged",
ext_opts = {
[types.choiceNode] = {
active = {
virt_text = { { "choiceNode", "Comment" } },
},
},
},
ext_base_prio = 300,
ext_prio_increase = 1,
enable_autosnippets = true,
store_selection_keys = "<Tab>",
})
require("luasnip.loaders.from_lua").lazy_load({
paths = { vim.fn.stdpath("config") .. "/lua/snippets/lua_snippets" },
})
require("luasnip.loaders.from_vscode").lazy_load({
paths = { vim.fn.stdpath("config") .. "/lua/snippets" },
})
end,
keys = {
{
"<tab>",
function()
return require("luasnip").jumpable(1) and "<Plug>luasnip-jump-next" or "<tab>"
end,
expr = true, silent = true, mode = "i",
},
{ "<tab>", function() require("luasnip").jump(1) end, mode = "s" },
{ "<s-tab>", function() require("luasnip").jump(-1) end, mode = { "i", "s" } },
},
},
{ "chrisgrieser/nvim-scissors", dependencies = {
"L3MON4D3/LuaSnip",
} },
}