From e00efd092205d45b6e7c12a9efb954b395fb4fe5 Mon Sep 17 00:00:00 2001 From: "Gustavo \"Guz\" L de Mello" Date: Sat, 14 Feb 2026 13:05:04 -0300 Subject: [PATCH] feat(conform): format command --- lua/dot/formatting.lua | 14 +++++++++++++- lua/dot/plugins.lua | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lua/dot/formatting.lua b/lua/dot/formatting.lua index 0636ce4..090326e 100644 --- a/lua/dot/formatting.lua +++ b/lua/dot/formatting.lua @@ -11,7 +11,7 @@ local function javascript_formatters(bufnr) if conform.get_formatter_info("prettierd", bufnr).available then table.insert(formatters, "prettierd") - elseif require("conform").get_formatter_info("prettier", bufnr).available then + elseif conform.get_formatter_info("prettier", bufnr).available then table.insert(formatters, "prettier") end @@ -81,3 +81,15 @@ conform.setup({ xmltidy = { inherit = false, command = "tidy", args = { "-xml", "-indent", "yes", "2", "-wrap", "100", "-" } }, -- INFO: Uses HTML Tidy }, }) + +vim.api.nvim_create_user_command("Format", function(args) + local range = nil + if args.count ~= -1 then + local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1] + range = { + start = { args.line1, 0 }, + ["end"] = { args.line2, end_line:len() }, + } + end + conform.format({ async = true, lsp_format = "fallback", range = range }) +end, { range = true }) diff --git a/lua/dot/plugins.lua b/lua/dot/plugins.lua index d5a042d..79b3cc3 100644 --- a/lua/dot/plugins.lua +++ b/lua/dot/plugins.lua @@ -40,8 +40,8 @@ lze.load({ after = function() require("dot.formatting") end, + cmd = { "ConformInfo", "Format" }, event = { "InsertLeave", "TextChanged" }, - on_require = "conform", }, { "guess-indent.nvim",