On LazyVim when I save a cpp file it is automatically formatted.

It is possible to disable/enable it in the session using Spaceuf

But I would like to disable that autoformatting on save functionality by default.

How to do that?

2 Answers 2


I received a warning using the above answer. Looks like it should be set in


vim.g.autoformat = false
  • 1
    That sets the vim option. What warning ? How does this affect lsp config?
    – D. Ben Knoble
    Commented Dec 19, 2023 at 23:37
  • 1
    nvim-lspconfig.opts.autoformat is deprecated. Please use vim.g.autoformat instead # stacktrace: - /LazyVim/lua/lazyvim/util/plugin.lua:93 in **** - vim/_editor.lua:0 Commented Dec 21, 2023 at 2:05
  • 2
    Great answer, can confirm this works - if anyone is curious, LazyVim is setting that here
    – kevlarr
    Commented Jan 10 at 21:46
  • Inside a session running as a command, prepend with lua, i.e. lua vim.g.autoformat = false.
    – SimonH
    Commented Mar 19 at 12:36
  • 1
    this answer should be accepted for the newer versions. vi.stackexchange.com/a/42598/20287 is deprecated Commented Apr 16 at 8:57

The auto-formatting on save is a LazyVim functionality associated to the nvim-lspconfig plugin.

To disable it you have to create a lua file in ~/.config/nvim/lua/plugins folder with the following content:


return {
    opts = {
      autoformat = false,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.