From ce9ae3617f5195a14388d7debaacd3d902b9bf68 Mon Sep 17 00:00:00 2001 From: punkfairie <23287005+punkfairie@users.noreply.github.com> Date: Fri, 23 Feb 2024 20:29:55 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20fix(nvim):=20Finally=20get=20custom?= =?UTF-8?q?=20snippets=20working?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config/nvim/lua/plugins/coding.lua | 10 +++ .config/nvim/lua/snippets/fish.lua | 100 ++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 .config/nvim/lua/plugins/coding.lua create mode 100644 .config/nvim/lua/snippets/fish.lua diff --git a/.config/nvim/lua/plugins/coding.lua b/.config/nvim/lua/plugins/coding.lua new file mode 100644 index 0000000..53e841e --- /dev/null +++ b/.config/nvim/lua/plugins/coding.lua @@ -0,0 +1,10 @@ +return { + { + "L3MON4D3/LuaSnip", + config = function(_, opts) + require("luasnip").setup(opts) + + require("luasnip.loaders.from_lua").lazy_load({ lazy_paths = { "~/.config/nvim/lua/snippets" } }) + end, + }, +} diff --git a/.config/nvim/lua/snippets/fish.lua b/.config/nvim/lua/snippets/fish.lua new file mode 100644 index 0000000..12c875f --- /dev/null +++ b/.config/nvim/lua/snippets/fish.lua @@ -0,0 +1,100 @@ +local ls = require("luasnip") +local s = ls.snippet +local t = ls.text_node +local i = ls.insert_node +local fmt = require("luasnip.extras.fmt").fmt + +return { + s({ trig = "#!", desc = "shebang" }, t("#!/usr/bin/env fish")), + + s( + { trig = "if", desc = "if ... end" }, + fmt( + [[ + if {} + {} + end + ]], + { i(1), i(0) } + ) + ), + + s( + { trig = "elif", desc = "else if ..." }, + fmt( + [[ + else if {} + {} + ]], + { i(1), i(0) } + ) + ), + + s( + { trig = "fori", desc = "for ... in ... end" }, + fmt( + [[ + for {} in {} + {} + end + ]], + { i(1), i(2), i(0) } + ) + ), + + s( + { trig = "wh", desc = "while ... end" }, + fmt( + [[ + while {} + {} + end + ]], + { i(1), i(0) } + ) + ), + + s( + { trig = "wht", desc = "while true ... end" }, + fmt( + [[ + while true + {} + end + ]], + { i(0) } + ) + ), + + s( + { trig = "sw", desc = "switch ... case ... end" }, + fmt( + [[ + switch {} + case {} + {} + end + ]], + { i(1), i(2), i(0) } + ) + ), + + s( + { trig = "func", desc = "function ... end" }, + fmt( + [[ + function {} + {} + end + ]], + { i(1), i(0) } + ) + ), + + s({ trig = "dn", desc = "&>/dev/null" }, t("&>/dev/null")), + + s( + { trig = "abbr", desc = "abbr -a ... --position ..." }, + fmt('abbr -a {} --position {} "{}"', { i(1), i(2, "command"), i(3) }) + ), +}