From 6ec3f9d0cd7e3fdb11c3946db04ef3ba7d6f7dfc Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 20 Nov 2023 23:49:51 +0100 Subject: nvim: Add snippet for include guards --- .config/nvim/after/plugin/luasnip.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to '.config/nvim/after') diff --git a/.config/nvim/after/plugin/luasnip.lua b/.config/nvim/after/plugin/luasnip.lua index 6d9d662..6bd0f26 100644 --- a/.config/nvim/after/plugin/luasnip.lua +++ b/.config/nvim/after/plugin/luasnip.lua @@ -11,6 +11,12 @@ local sn = ls.snippet_node local t = ls.text_node local fmt = require('luasnip.extras.fmt').fmt +local function same(index) + return f(function(args) + return args[1] + end, { index }) +end + ls.config.set_config { history = true, updateevents = 'TextChanged,TextChangedI', @@ -181,6 +187,24 @@ ls.add_snippets('go', { ), }) + +ls.add_snippets('c', { + s( + 'gu', + fmt( + [[ + #ifndef {}_H + #define {}_H + + {} + + #endif /* !{}_H */ + ]], + { i(1), same(1), i(0), same(1), } + ) + ), +}) + vim.keymap.set({ 'i', 's' }, '', function() if ls.expand_or_jumpable() then ls.expand_or_jump() -- cgit v1.2.3