diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-11-04 07:35:34 +0100 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-11-04 07:35:34 +0100 |
commit | 379cd763460659bfdbd49386108a9a5ab68663c2 (patch) | |
tree | 8778abcf5ee27a6e781e5179fd4d6ef0b6ee9523 /after | |
parent | 68b90b79f06a0fa09866f35e84e4c72405ac547d (diff) |
checkpoint
Diffstat (limited to 'after')
-rw-r--r-- | after/ftplugin/c.lua | 5 | ||||
-rw-r--r-- | after/plugin/conform.lua | 76 | ||||
-rw-r--r-- | after/plugin/luasnip.lua | 63 |
3 files changed, 42 insertions, 102 deletions
diff --git a/after/ftplugin/c.lua b/after/ftplugin/c.lua index b5b06d0..0b5c163 100644 --- a/after/ftplugin/c.lua +++ b/after/ftplugin/c.lua @@ -16,4 +16,7 @@ map("n", ",i", function() vim.cmd("normal ''") end, { desc = "Include header for word under cursor" }) map("n", ",f", mapcmd("CF"), { desc = "Toggle formatting" }) -vim.o.commentstring = "// %s" + +vim.opt.commentstring = "// %s" +-- disable indent in switch statement +vim.opt.cinoptions = "l1" diff --git a/after/plugin/conform.lua b/after/plugin/conform.lua index 7a8bbce..643743f 100644 --- a/after/plugin/conform.lua +++ b/after/plugin/conform.lua @@ -12,42 +12,42 @@ conform.setup({ }, }) -conform.formatters["clang-format"] = { - prepend_args = { - "--style", - "{" - .. "IndentWidth: 4, " - .. "AlignAfterOpenBracket: BlockIndent, " - .. "AlignArrayOfStructures: Right, " - .. "BreakBeforeBraces: Linux, " - .. "PointerAlignment: Left," - .. "AllowShortIfStatementsOnASingleLine: true, " - .. "AllowShortLoopsOnASingleLine: true, " - .. "AllowAllArgumentsOnNextLine: true, " - .. "AllowShortCaseLabelsOnASingleLine: true, " - .. "BreakAfterReturnType: AllDefinitions, " - .. "ColumnLimit: " - .. vim.o.tw - .. "}", - }, -} +-- conform.formatters["clang-format"] = { +-- prepend_args = { +-- "--style", +-- "{" +-- .. "IndentWidth: 4, " +-- .. "AlignAfterOpenBracket: BlockIndent, " +-- .. "AlignArrayOfStructures: Right, " +-- .. "BreakBeforeBraces: Linux, " +-- .. "PointerAlignment: Left," +-- .. "AllowShortIfStatementsOnASingleLine: true, " +-- .. "AllowShortLoopsOnASingleLine: true, " +-- .. "AllowAllArgumentsOnNextLine: true, " +-- .. "AllowShortCaseLabelsOnASingleLine: true, " +-- .. "AlwaysBreakAfterReturnType: AllDefinitions, " +-- .. "ColumnLimit: " +-- .. vim.o.tw +-- .. "}", +-- }, +-- } --- ID of autocmd for CFormat -vim.b.CFormatID = nil --- Enable formatting on save for C only when using the :CFormat command -vim.api.nvim_create_user_command("CFormat", function() - if vim.b.CFormatID == nil then - vim.b.CFormatID = vim.api.nvim_create_autocmd("BufWritePre", { - buffer = 0, - callback = function() - conform.format({ formatters = { "clang-format" } }) - end, - }) - conform.format({ formatters = { "clang-format" } }) - print("Auto formatting enabled.") - else - vim.api.nvim_del_autocmd(vim.b.CFormatID) - print("Auto formatting disabled.") - vim.b.CFormatID = nil - end -end, {}) +-- -- ID of autocmd for CFormat +-- vim.b.CFormatID = nil +-- -- Enable formatting on save for C only when using the :CFormat command +-- vim.api.nvim_create_user_command("CFormat", function() +-- if vim.b.CFormatID == nil then +-- vim.b.CFormatID = vim.api.nvim_create_autocmd("BufWritePre", { +-- buffer = 0, +-- callback = function() +-- conform.format({ formatters = { "clang-format" } }) +-- end, +-- }) +-- conform.format({ formatters = { "clang-format" } }) +-- print("Auto formatting enabled.") +-- else +-- vim.api.nvim_del_autocmd(vim.b.CFormatID) +-- print("Auto formatting disabled.") +-- vim.b.CFormatID = nil +-- end +-- end, {}) diff --git a/after/plugin/luasnip.lua b/after/plugin/luasnip.lua deleted file mode 100644 index 4b88ca9..0000000 --- a/after/plugin/luasnip.lua +++ /dev/null @@ -1,63 +0,0 @@ -local ls = require("luasnip") - -local map = vim.keymap.set -local parse_snippet = ls.parser.parse_snippet - -map({ "i", "s" }, "<C-h>", function() - if ls.expand_or_locally_jumpable() then - ls.expand_or_jump() - end -end, { silent = true }) -map({ "i", "s" }, "<C-l>", function() - if ls.locally_jumpable(-1) then - ls.jump(-1) - end -end, { silent = true }) -map({ "i", "s" }, "<C-c>", function() - if ls.choice_active() then - ls.change_choice(1) - end -end, { silent = true }) - --- temporary keybind to play around -map("n", " s", "<cmd>source ~/.config/nvim/after/plugin/luasnip.lua<cr>") - -ls.config.set_config({ - history = true, - -- Will update multiple nodes at the same time when in insert mode - update_events = { "TextChanged", "TextChangedI" }, -}) - -ls.add_snippets("go", { - parse_snippet("main", "package main\n\nfunc main() {\n\t$0\n}"), - parse_snippet("e", "if err != nil {\n\tpanic(err)$1\n}\n$0"), - parse_snippet("ee", "if err != nil {\n\tfmt.Fprintln(os.Stderr, err)$1\n\tos.Exit(${2:1})\n}\n$0"), - parse_snippet("eif", "if err := $1; err != nil {\n\tfmt.Println(err)$2\n}\n$0"), - parse_snippet("pf", "fmt.Printf($0)"), - parse_snippet("pl", "fmt.Println($0)"), -}) -ls.add_snippets("sh", { - parse_snippet("!", "#!/bin/sh\n$0"), - parse_snippet("if", "if ${1:condition}; then\n\t$0\nfi"), - parse_snippet("while", "while ${1:condition}; do\n\t$0\ndone"), - parse_snippet("for", "for ${1:v} in ${2:list}; do\n\t$0\ndone"), - parse_snippet("case", "case ${1:\\$var} in\n\t$0\nesac"), -}) -ls.add_snippets("c", { - parse_snippet("main", "int main(void) {\n\t$0\n\treturn 0;\n}"), - parse_snippet( - "uints", - [[#include <stdint.h> -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; -typedef uint64_t u64; -typedef int8_t s8; -typedef int16_t s16; -typedef int32_t s32; -typedef int64_t s64; -]] - ), -}) -ls.add_snippets("typescript", { parse_snippet("cl", "console.log($0);") }) -ls.add_snippets("html", { parse_snippet("t", [[<$1>$0</$1>]]) }) |