0

There is a not-so-well formatted text file (c# code). Some lines in this file contain trailing spaces.

I do not want to fix these trailing spaces (let 'git blame' blame those who wrote these lines!)

However, when I open the file with nvim and save the file all the trailing spaces are gone. (After I open the file trailing spaces are present, but after ':w' they are gone)

This is very strange because:

  1. even if I open the file with '-b' and/or '--clean' options nvim removes trailing spaces. (according to help '--clean' option tells nvim not to load my rc or any 'external' plugins, built-in plugins are still loaded)
  2. if I open the file with '-u NONE' option nvim does not remove trailing spaces (according to help, even built-in plugins are not loaded in this case)
  3. if I move the file to a different directory nvim does not remove trailing spaces (!!!). Looks like that spaces are removed if the file remains in the same git repo - when I move the file to a different git repo and spaces are not removed.
  4. Looks like the current working directory doesn't affect this behavior.

NVIM v0.9.1, OS - Windows.

Any ideas what is going on and how to suppress this feature?

1
  • "I do not want to fix these trailing spaces (let 'git blame' blame those who wrote these lines!)" - or you could follow the boy scout rule and fix whitespace throughout the project. Let git blame credit you for improving the project for everybody.
    – Friedrich
    Oct 5, 2023 at 9:07

1 Answer 1

1

Sounds like your file is in a repository that contains an EditorConfig file with the trim_trailing_whitespace setting set to true. Neovim will detect this file, and then apply the contained rules to your files, removing the trailing whitespace on save.

You can disable this feature by adding the following line to your Neovim config:

vim.g.editorconfig = false

...or you can find the .editorconfig file which is causing this behaviour and remove the trim_trailing_whitespace setting.

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.