From f35c6599c0d1eac32aba09a737b3f49ed5c2268d Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Thu, 9 Dec 2021 16:47:22 +0100 Subject: [PATCH] [nvim] feat: c snippets --- .config/nvim/after/ftplugin/c.lua | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/.config/nvim/after/ftplugin/c.lua b/.config/nvim/after/ftplugin/c.lua index 6dfd3f6..ad16ca6 100644 --- a/.config/nvim/after/ftplugin/c.lua +++ b/.config/nvim/after/ftplugin/c.lua @@ -3,7 +3,49 @@ -- License : GPLv3 -- Description : c settings file + local opt = vim.opt local g = vim.g opt.formatoptions = "trq1jp" + +-- Snippets +local ls = require("luasnip") + +-- some shorthands... +local s = ls.snippet +local t = ls.text_node +local i = ls.insert_node +local f = ls.function_node + +local copy = utils.copy + +ls.snippets = { + c = { + s("main", { + t({ "int main(int argc, char* argv[])" }), + t({ "", "{", "\t" }), + i(0), + t({ "", "\treturn 0;"}), + t({ "", "}"}), + }), + s("fn", { + -- Simple static text. + t("//Parameters: "), + -- function, first parameter is the function, second the Placeholders + -- whose text it gets as input. + f(copy, 2), + t({ "", "" }), + -- Placeholder/Insert. + i(1), + t("("), + -- Placeholder with initial text. + i(2, "int foo"), + -- Linebreak + t({ ")", "{", "\t" }), + i(0), + t({ "", "\treturn 0;"}), + t({ "", "}"}), + }), + }, +}