X-Git-Url: https://git.rmz.io/dotfiles.git/blobdiff_plain/b99dee25318e48024313b76e075a24afccd0c10b..11b9e4b2c7692dd5b3f645f2257057c676063cdf:/nvim/lua/plugins/formatter.lua diff --git a/nvim/lua/plugins/formatter.lua b/nvim/lua/plugins/formatter.lua new file mode 100644 index 0000000..2dd44ab --- /dev/null +++ b/nvim/lua/plugins/formatter.lua @@ -0,0 +1,47 @@ +--- TODO: add toggle for format on save +--- https://github.com/stevearc/conform.nvim/blob/master/doc/recipes.md#command-to-toggle-format-on-save +--- previous keymap was uf + +---@type LazySpec +return { + { "stevearc/conform.nvim", + dependencies = { "mason.nvim" }, + lazy = true, + cmd = "ConformInfo", + keys = { + {"cf", function() require("conform").format({ async = true }) end, mode = "", desc = "Format buffer" }, + { + "cF", + function() + require("conform").format({ formatters = { "injected" }, timeout_ms = 3000 }) + end, + mode = { "n", "v" }, + desc = "Format Injected Langs", + }, + }, + ---@module "conform" + ---@type conform.setupOpts + opts = { + default_format_opts = { + timeout_ms = 3000, + async = false, -- not recommended to change + quiet = false, -- not recommended to change + lsp_format = "fallback", -- not recommended to change + }, + formatters_by_ft = { + lua = { "stylua" }, + fish = { "fish_indent" }, + sh = { "shfmt" }, + }, + -- The options you set here will be merged with the builtin formatters. + -- You can also define any custom formatters here. + ---@type table + formatters = { + injected = { options = { ignore_errors = true } }, + }, + }, + init = function () + vim.opt.formatexpr = "v:lua.require'conform'.formatexpr()" + end, + }, +}