From 1f2dad0be57a20bca63b251d0b22c57839a6f794 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Thu, 8 Jan 2026 17:25:42 +0100 Subject: Neovim: Benutze conform.nvim als Standard-Formater --- nvim/ftplugin/sh.lua | 4 ++++ nvim/lua/config/keymaps.lua | 5 ++++- nvim/lua/plugins/format.lua | 20 ++++++++++++++++++++ nvim/lua/plugins/lsp.lua | 16 ++++++++++++++++ nvim/stylua.toml | 13 +++++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 nvim/ftplugin/sh.lua create mode 100644 nvim/lua/plugins/format.lua create mode 100644 nvim/stylua.toml (limited to 'nvim') diff --git a/nvim/ftplugin/sh.lua b/nvim/ftplugin/sh.lua new file mode 100644 index 0000000..cda52f1 --- /dev/null +++ b/nvim/ftplugin/sh.lua @@ -0,0 +1,4 @@ +local opt = vim.opt_local + +opt.expandtab = true +opt.shiftwidth = 2 diff --git a/nvim/lua/config/keymaps.lua b/nvim/lua/config/keymaps.lua index 6cc998d..a665e82 100644 --- a/nvim/lua/config/keymaps.lua +++ b/nvim/lua/config/keymaps.lua @@ -16,7 +16,10 @@ function M.lsp(buffer, client) map("n", "rn", vim.lsp.buf.rename, opts) map("n", "ca", vim.lsp.buf.code_action, opts) map("n", "cf", function() - vim.lsp.buf.format({ async = true; }) + require("conform").format({ + async = true, + lsp_fallback = true, + }) end, opts) if client and client.name == "clangd" then diff --git a/nvim/lua/plugins/format.lua b/nvim/lua/plugins/format.lua new file mode 100644 index 0000000..bdfaf03 --- /dev/null +++ b/nvim/lua/plugins/format.lua @@ -0,0 +1,20 @@ +return { + "stevearc/conform.nvim", + event = { "BufReadPre", "BufNewFile" }, + opts = { + formatters_by_ft = { + sh = { "shfmt" }, -- brew install + bash = { "shfmt" }, + python = { "ruff_format", "black" }, -- brew install ruff + lua = { "stylua" }, -- brew install stylua + typescript = { "prettierd", "prettier" }, + javascript = { "prettierd", "prettier" }, + json = { "jq" }, -- brew install jq + -- cpp = { "clang_format" }, + }, + }, + + config = function(_, opts) + require("conform").setup(opts) + end, +} diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua index 4c549a7..30e3924 100644 --- a/nvim/lua/plugins/lsp.lua +++ b/nvim/lua/plugins/lsp.lua @@ -20,6 +20,22 @@ return { }, } + vim.lsp.config.bashls = { + settings = { + bashIde = { + shellcheck = { + enable = true, + severity = { + error = "error", + warning = "warning", + info = "info", + }, + }, + globPattern = "**/*.sh", + }, + }, + } + vim.lsp.enable({ "bashls", -- npm install -g bash-language-server "clangd", -- pkg install llvm diff --git a/nvim/stylua.toml b/nvim/stylua.toml new file mode 100644 index 0000000..28b83c7 --- /dev/null +++ b/nvim/stylua.toml @@ -0,0 +1,13 @@ +syntax = "All" +column_width = 120 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 2 +quote_style = "AutoPreferDouble" +call_parentheses = "Always" +collapse_simple_statement = "ConditionalOnly" +space_after_function_names = "Never" +block_newline_gaps = "Never" + +[sort_requires] +enabled = false -- cgit v1.3