conform.lua 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. -- formart 格式化
  2. return {
  3. "stevearc/conform.nvim",
  4. event = { "BufWritePre" },
  5. cmd = { "ConformInfo" },
  6. keys = {
  7. {
  8. -- Customize or remove this keymap to your liking
  9. "<leader>f",
  10. function()
  11. require("conform").format({ async = true, lsp_fallback = true })
  12. end,
  13. mode = "",
  14. desc = "Format buffer",
  15. },
  16. },
  17. -- Everything in opts will be passed to setup()
  18. opts = {
  19. -- Define your formatters
  20. formatters_by_ft = {
  21. lua = { "stylua" },
  22. python = { "isort", "black" },
  23. html = { 'htmlbeautifier' },
  24. css = { 'stylelint' },
  25. yaml = { 'yamlfix' },
  26. shell = { 'shellcheck' },
  27. json = { "ixjson" },
  28. javascript = { { "prettierd", "prettier" } }
  29. },
  30. -- Set up format-on-save
  31. format_on_save = { timeout_ms = 100, lsp_fallback = true },
  32. -- Customize formatters
  33. formatters = {
  34. shfmt = {
  35. prepend_args = { "-i", "2" },
  36. },
  37. },
  38. },
  39. init = function()
  40. -- If you want the formatexpr, here is the place to set it
  41. vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
  42. end,
  43. }