Neovim auto-formatter for C, Go, Zig, Lua, Python and Shell

This commit is contained in:
Fabio Scotto di Santolo
2025-08-03 23:16:09 +02:00
parent 6e737cdfb0
commit 04fa2edff8
2 changed files with 60 additions and 0 deletions

View File

@@ -1,6 +1,8 @@
{ {
"extras": [ "extras": [
"lazyvim.plugins.extras.dap.core", "lazyvim.plugins.extras.dap.core",
"lazyvim.plugins.extras.editor.dial",
"lazyvim.plugins.extras.editor.fzf",
"lazyvim.plugins.extras.editor.refactoring", "lazyvim.plugins.extras.editor.refactoring",
"lazyvim.plugins.extras.editor.telescope", "lazyvim.plugins.extras.editor.telescope",
"lazyvim.plugins.extras.lang.clangd", "lazyvim.plugins.extras.lang.clangd",
@@ -12,6 +14,7 @@
"lazyvim.plugins.extras.lang.toml", "lazyvim.plugins.extras.lang.toml",
"lazyvim.plugins.extras.lang.yaml", "lazyvim.plugins.extras.lang.yaml",
"lazyvim.plugins.extras.lang.zig", "lazyvim.plugins.extras.lang.zig",
"lazyvim.plugins.extras.lsp.none-ls",
"lazyvim.plugins.extras.ui.alpha" "lazyvim.plugins.extras.ui.alpha"
], ],
"install_version": 7, "install_version": 7,

View File

@@ -0,0 +1,57 @@
return {
"nvimtools/none-ls.nvim",
config = function()
local null_ls = require("null-ls")
null_ls.setup({
sources = {
-- C
null_ls.builtins.formatting.clang_format.with({
extra_args = {
"--style={BasedOnStyle: LLVM, IndentWidth: 8, TabWith: 8, UseTab: Always, BreakBeforeBraces: Linux, AllowShortIfStatementsOnASingleLine: false, AllowShortLoopsOnASingleLine: false, AllowShortFunctionsOnASingleLine: InlineOnly, ColumnLimit: 80, AlignConsecutiveDeclarations: false, AlignConsecutiveAssignments: false, AlignEscapedNewlines: Left, AlignOperands: false, IndentCaseLabels: false, SpaceBeforeParens: ControlStatements }",
},
}),
-- Go
null_ls.builtins.formatting.goimports,
-- Zig
null_ls.builtins.formatting.zigfmt,
-- Lua
null_ls.builtins.formatting.stylua.with({
extra_args = {
"--indent-type",
"Spaces",
"--indent-width",
"4",
"--column-width",
"100",
},
}),
-- Python
null_ls.builtins.formatting.black.with({
extra_args = { "--line-length", "79" },
}),
-- Shell
null_ls.builtins.formatting.shfmt.with({
extra_args = { "-i", "2", "-ci", "-bn", "-sr", "-p" },
}),
},
-- Auto-format on save
on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = bufnr,
callback = function()
vim.lsp.buf.format({ async = false })
end,
})
end
end,
})
end,
}