]> git.rmz.io Git - dotfiles.git/blob - nvim/lua/plugins/formatter.lua
Merge branch 'remove-lazyvim'
[dotfiles.git] / nvim / lua / plugins / formatter.lua
1 --- TODO: add toggle for format on save
2 --- https://github.com/stevearc/conform.nvim/blob/master/doc/recipes.md#command-to-toggle-format-on-save
3 --- previous keymap was <leader>uf
4
5 ---@type LazySpec
6 return {
7 { "stevearc/conform.nvim",
8 dependencies = { "mason.nvim" },
9 lazy = true,
10 cmd = "ConformInfo",
11 keys = {
12 {"<leader>cf", function() require("conform").format({ async = true }) end, mode = "", desc = "Format buffer" },
13 {
14 "<leader>cF",
15 function()
16 require("conform").format({ formatters = { "injected" }, timeout_ms = 3000 })
17 end,
18 mode = { "n", "v" },
19 desc = "Format Injected Langs",
20 },
21 },
22 ---@module "conform"
23 ---@type conform.setupOpts
24 opts = {
25 default_format_opts = {
26 timeout_ms = 3000,
27 async = false, -- not recommended to change
28 quiet = false, -- not recommended to change
29 lsp_format = "fallback", -- not recommended to change
30 },
31 formatters_by_ft = {
32 lua = { "stylua" },
33 fish = { "fish_indent" },
34 sh = { "shfmt" },
35 },
36 -- The options you set here will be merged with the builtin formatters.
37 -- You can also define any custom formatters here.
38 ---@type table<string, conform.FormatterConfigOverride|fun(bufnr: integer): nil|conform.FormatterConfigOverride>
39 formatters = {
40 injected = { options = { ignore_errors = true } },
41 },
42 },
43 init = function ()
44 vim.opt.formatexpr = "v:lua.require'conform'.formatexpr()"
45 end,
46 },
47 }