5

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

8

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:

~/.config/nvim/lua/plugins/lazyvim.lua

return {
  {
    "neovim/nvim-lspconfig",
    opts = {
      autoformat = false,
    },
  },
}
4

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

~/.config/nvim/lua/config/options.lua

vim.g.autoformat = false
4
  • 1
    That sets the vim option. What warning ? How does this affect lsp config?
    – D. Ben Knoble
    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 Dec 21, 2023 at 2:05
  • Great answer, can confirm this works - if anyone is curious, LazyVim is setting that here
    – kevlarr
    Jan 10 at 21:46
  • Inside a session running as a command, prepend with lua, i.e. lua vim.g.autoformat = false.
    – SimonH
    Mar 19 at 12:36

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.