diff --git a/lua/core/autocmds.lua b/lua/core/autocmds.lua new file mode 100644 index 0000000..229159c --- /dev/null +++ b/lua/core/autocmds.lua @@ -0,0 +1,24 @@ +local group = vim.api.nvim_create_augroup("IndentFormatOnSave", { clear = true }) + +vim.api.nvim_create_autocmd("BufWritePre", { + group = group, + callback = function(args) + local ft = vim.bo[args.buf].filetype + local indent_filetypes = { + c = true, + cpp = true, + h = true, + hpp = true, + } + + if not indent_filetypes[ft] then + return + end + + local view = vim.fn.winsaveview() + vim.api.nvim_buf_call(args.buf, function() + vim.cmd("silent keepjumps normal! gg=G") + end) + vim.fn.winrestview(view) + end, +}) diff --git a/lua/core/init.lua b/lua/core/init.lua index e7f236d..a100132 100644 --- a/lua/core/init.lua +++ b/lua/core/init.lua @@ -1,3 +1,4 @@ require("core.options") require("core.keymaps") +require("core.autocmds") require("core.lazy") diff --git a/lua/plugins/config/conform.lua b/lua/plugins/config/conform.lua deleted file mode 100644 index da995c7..0000000 --- a/lua/plugins/config/conform.lua +++ /dev/null @@ -1,34 +0,0 @@ -local conform = require("conform") - -conform.setup({ - formatters_by_ft = { - c = { "clang_format" }, - cpp = { "clang_format" }, - h = { "clang_format" }, - hpp = { "clang_format" }, - }, - format_on_save = function(bufnr) - local ft = vim.bo[bufnr].filetype - local cpp_filetypes = { - c = true, - cpp = true, - h = true, - hpp = true, - } - - if cpp_filetypes[ft] then - return { - timeout_ms = 1000, - lsp_format = "fallback", - } - end - end, -}) - -vim.api.nvim_create_user_command("Format", function() - conform.format({ - async = false, - timeout_ms = 1000, - lsp_format = "fallback", - }) -end, {}) diff --git a/lua/plugins/config/dap.lua b/lua/plugins/config/dap.lua index f7250ca..f687e3f 100644 --- a/lua/plugins/config/dap.lua +++ b/lua/plugins/config/dap.lua @@ -2,7 +2,9 @@ local dap = require("dap") local dapui = require("dapui") local function resolve_codelldb() - local mason_codelldb = vim.fn.stdpath("data") .. "/mason/bin/codelldb" + local is_windows = vim.fn.has("win32") == 1 + local mason_codelldb = vim.fn.stdpath("data") + .. (is_windows and "/mason/bin/codelldb.cmd" or "/mason/bin/codelldb") if vim.fn.executable(mason_codelldb) == 1 then return mason_codelldb end @@ -12,7 +14,7 @@ local function resolve_codelldb() return system_codelldb end - return "codelldb" + return is_windows and "codelldb.cmd" or "codelldb" end require("nvim-dap-virtual-text").setup({ diff --git a/lua/plugins/config/opencode.lua b/lua/plugins/config/opencode.lua index 3f35550..836bc1e 100644 --- a/lua/plugins/config/opencode.lua +++ b/lua/plugins/config/opencode.lua @@ -9,3 +9,7 @@ vim.o.autoread = true vim.keymap.set({ "n", "x" }, "oa", function() require("opencode").ask("@this: ", { submit = true }) end, { desc = "Ask opencode with selection" }) + +vim.keymap.set({ "n", "t" }, "ot", function() + require("opencode").toggle() +end, { desc = "Toggle opencode" }) diff --git a/lua/plugins/config/whichkey.lua b/lua/plugins/config/whichkey.lua index 949ec66..a1415f2 100644 --- a/lua/plugins/config/whichkey.lua +++ b/lua/plugins/config/whichkey.lua @@ -24,6 +24,7 @@ if wk.add then { "f", group = "Find" }, { "m", group = "Build" }, { "o", group = "OpenCode" }, + { "ot", desc = "Toggle opencode" }, { "t", group = "Tests" }, { "x", group = "Problems" }, }) @@ -33,7 +34,10 @@ else d = { name = "+Debug" }, f = { name = "+Find" }, m = { name = "+Build" }, - o = { name = "+OpenCode" }, + o = { + name = "+OpenCode", + t = "Toggle opencode", + }, t = { name = "+Tests" }, x = { name = "+Problems" }, }, { prefix = "" }) diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 13fb1b0..bdd5de2 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -68,12 +68,6 @@ return { require("plugins.config.cmp") end, }, - { - "stevearc/conform.nvim", - config = function() - require("plugins.config.conform") - end, - }, { 'nvim-telescope/telescope.nvim', tag = '0.1.8', dependencies = { 'nvim-lua/plenary.nvim' }