Simple auto formatter that prefers `null-ls` over LSP.
fix: Typo in README
fix: Revert last change, fix is to load plugin on BufReadPre
fix: Don't run without a filetype


browse  log 



You can also use your local clone with git send-email.

GitHub code size in bytes Lines of code

Open an issue here | mirrored on GitHub


Extremely simple auto format plugin.

We're creating an autocmd that runs on BufWritePre - the primary function of this plugin is to prefer null-ls for formatting over our LSP client.

On BufWritePre events, in the event that null-ls is present, we check if a formatting source has been registered for the filetype of the buffer being saved. If there is, we run the null-ls formatter, otherwise, we try our LSP client.

In case you need a larger timeout duration, you can configure it. If you'd prefer to not auto format certain filetypes, they can be defined. If you'd like to prefer LSP client formatting, then remove the null-ls formatting source honestly, but for some reason I've provided an option to prefer_lsp for some filetypes.



  event = "BufWinEnter",
  config = function()


  config = function()


Plug 'https://git.sr.ht/~nedia/auto-format.nvim'
lua require("auto-format").setup()


  -- The name of the augroup.
  augroup_name = "AutoFormat",

  -- If formatting takes longer than this amount of time, it will fail. Having no
  -- timeout at all tends to be ugly - larger files, complex or poor formatters
  -- will struggle to format within whatever the default timeout
  -- `vim.lsp.buf.format` uses.
  timeout = 2000,

  -- These filetypes will not be formatted automatically.
  exclude_ft = {},

  -- Prefer formatting via LSP for these filetypes.
  prefer_lsp = {},