Advertisement
Guest User

neovim autoformat

a guest
Jan 1st, 2025
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | Source Code | 0 0
  1.   { -- Autoformat
  2.     'stevearc/conform.nvim',
  3.     event = { 'BufWritePre' },
  4.     cmd = { 'ConformInfo' },
  5.     keys = {
  6.       {
  7.         '<leader>f',
  8.         function()
  9.           require('conform').format { async = true, lsp_fallback = true }
  10.         end,
  11.         mode = '',
  12.         desc = '[F]ormat buffer',
  13.       },
  14.     },
  15.     opts = {
  16.       notify_on_error = false,
  17.       format_on_save = function(bufnr)
  18.         -- Disable "format_on_save lsp_fallback" for languages that don't
  19.         -- have a well standardized coding style. You can add additional
  20.         -- languages here or re-enable it for the disabled ones.
  21.         local disable_filetypes = { c = true, cpp = true }
  22.         return {
  23.           timeout_ms = 500,
  24.           lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype],
  25.         }
  26.       end,
  27.       formatters_by_ft = {
  28.         lua = { 'stylua' },
  29.         -- Conform can also run multiple formatters sequentially
  30.         python = { 'isort', 'black' },
  31.         --
  32.         -- You can use 'stop_after_first' to run the first available formatter from the list
  33.         javascriptreact = { { 'prettierd', 'prettier' }, { 'eslint_d', 'eslint' } },
  34.         javascript = { 'prettierd', 'prettier', stop_after_first = true },
  35.         { 'eslint_d', 'eslint', stop_after_first = true },
  36.       },
  37.       typescript = {
  38.         { 'prettierd', 'prettier', stop_after_first = true },
  39.         { 'eslint_d', 'eslint', stop_after_first = true },
  40.         typescriptreact = { { 'prettierd', 'prettier' }, { 'eslint_d', 'eslint' } },
  41.       },
  42.     },
  43.   },
Tags: neovim
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement