summaryrefslogtreecommitdiff
path: root/lua/ben/plugins/formatting.lua
blob: 22ddb17e1bef444e10c02684795a5574e2beeace (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
return {
  "stevearc/conform.nvim",
  event = { "BufReadPre", "BufNewFile" },
  config = function()
    local conform = require("conform")

    conform.setup({
      formatters_by_ft = {
        javascript = { "prettier" },
        html = { "prettier" },
        css = { "prettier" },
        json = { "prettier" },
        markdown = { "prettier" },
        bib = { "bibtex_tidy" },
        go = { "goimports", "gci", "golines" },
        sh = { "shfmt" },
        tex = { "latexindent" },
        sql = { "sql_formatter" },
        python = { "isort", "black" },
        yaml = { "yamlfix" },
        lua = { "stylua" },
      },

      format_on_save = {
        lsp_fallback = true,
        async = false,
        timeout_ms = 300,
      },
    })
    vim.keymap.set({ "n", "v" }, "<leader>mp", function()
      conform.format({
        lsp_fallback = true,
        async = false,
        timeout_ms = 300,
      })
    end, { desc = "Format file or range" })
  end,
}