Beginner luasnip configuration for terraform
This commit is contained in:
parent
1961395687
commit
0f59972f1b
@ -34,7 +34,8 @@ ls.config.set_config {
|
||||
|
||||
-- Expand if expandable, or jump forward if jumpable
|
||||
-- If neither, do nothing queitly
|
||||
vim.keymap.set({ "i", "s" }, "<C-K>", function()
|
||||
-- vim.keymap.set({ "i", "s" }, "<C-K>", function()
|
||||
vim.keymap.set({ "i", "s" }, "<Tab>", function()
|
||||
if ls.expand_or_jumpable() then
|
||||
ls.expand_or_jump()
|
||||
end
|
||||
@ -42,41 +43,56 @@ end, { silent = true })
|
||||
-- end, { silent = true })
|
||||
|
||||
-- Jump backwards to the previous jumpable point
|
||||
vim.keymap.set({ "i", "s" }, "<C-J>", function()
|
||||
-- vim.keymap.set({ "i", "s" }, "<C-J>", function()
|
||||
vim.keymap.set({ "i", "s" }, "<S-Tab>", function()
|
||||
if ls.jumpable(-1) then
|
||||
ls.jump(-1)
|
||||
end
|
||||
end, { silent = true })
|
||||
|
||||
-- Selecting from a list of options in a choice node
|
||||
vim.keymap.set({ "i" }, "<C-L>", function()
|
||||
-- vim.keymap.set({ "i" }, "<C-L>", function()
|
||||
vim.keymap.set({ "i" }, "<A-Tab>", function()
|
||||
if ls.choice_active() then
|
||||
ls.change_choice(1)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Allow us to hot reload snippets
|
||||
vim.keymap.set("n", "<leader><leader>s", "<cmd>source ~/.config/nvim/lua/user/luasnip.lua<CR>")
|
||||
-- Allow us to hot reload snippets by unloading snippets then resourcing file
|
||||
local ls_cleanup = function()
|
||||
ls.cleanup()
|
||||
vim.cmd("source ~/.config/nvim/lua/user/luasnip.lua")
|
||||
end
|
||||
vim.keymap.set("n", "<leader><leader>s", ls_cleanup)
|
||||
|
||||
ls.add_snippets('lua', {
|
||||
ls.parser.parse_snippet("expand", "-- this is what was expanded!"),
|
||||
ls.parser.parse_snippet("lf", "local $1 = function($2)\n $0\nend"),
|
||||
ls.parser.parse_snippet("mf", "$1.$2 = function($3)\n $0\nend"),
|
||||
-- Example from snippet writing guide: https://github.com/L3MON4D3/LuaSnip/blob/master/Examples/snippets.lua#L190
|
||||
s(
|
||||
"fmt1",
|
||||
fmt("To {title} {} {}.", {
|
||||
i(2, "Name"),
|
||||
i(3, "Surname"),
|
||||
title = c(1, { t("Mr."), t("Ms.") }),
|
||||
})
|
||||
),
|
||||
-- Example from video: https://www.youtube.com/watch?v=Dn800rlPIho
|
||||
s(
|
||||
"req",
|
||||
fmt("local {} = require('{}')", {
|
||||
i(1, "default"),
|
||||
rep(1)
|
||||
})
|
||||
),
|
||||
ls.add_snippets(nil, {
|
||||
terraform = {
|
||||
ls.parser.parse_snippet("res", "resource \"$1\" \"$2\" {\n $3\n}"),
|
||||
ls.parser.parse_snippet("dat", "data \"$1\" \"$2\" {\n $3\n}"),
|
||||
ls.parser.parse_snippet("var", "variable \"$1\" {\n type = $2\n description = $3\n}"),
|
||||
ls.parser.parse_snippet("loc", "locals {\n $1\n}"),
|
||||
ls.parser.parse_snippet("mod", "module {\n source = $1\n}"),
|
||||
},
|
||||
lua = {
|
||||
ls.parser.parse_snippet("expand", "-- this is what was expanded!"),
|
||||
ls.parser.parse_snippet("lf", "local $1 = function($2)\n $0\nend"),
|
||||
ls.parser.parse_snippet("mf", "$1.$2 = function($3)\n $0\nend"),
|
||||
-- Example from snippet writing guide: https://github.com/L3MON4D3/LuaSnip/blob/master/Examples/snippets.lua#L190
|
||||
s(
|
||||
"fmt1",
|
||||
fmt("To {title} {} {}.", {
|
||||
i(2, "Name"),
|
||||
i(3, "Surname"),
|
||||
title = c(1, { t("Mr."), t("Ms.") }),
|
||||
})
|
||||
),
|
||||
-- Example from video: https://www.youtube.com/watch?v=Dn800rlPIho
|
||||
s(
|
||||
"req",
|
||||
fmt("local {} = require('{}')", {
|
||||
i(1, "default"),
|
||||
rep(1)
|
||||
})
|
||||
),
|
||||
}
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user