I am currently trying to edit a git hunk file (a diff: .git/addp-hunk-edit.diff), and to say to git that a line containing whitespace is unchanged it needs to have (a line with a single space) as its first character. The problem is that Vim removes all whitespace in otherwise empty lines as soon as I save the file!

This only happens on this file type, not for for instance .vimrc. How can I manually disable this behavior, and even better, permanently disable it for diff files?

  • MacVim 7.4.77, installed via Homebrew.
  • My .vimrc

1 Answer 1


Since there was nothing explicit in my .vimrc that acted on only-whitespace lines and the diff syntax file did no such thing either, this had to with my plugins somehow. I find out that I had an EditorConfig file in this project, and in it it had these lines:

# other
trim_trailing_whitespace = true

I then subsequently added a section for diff files

trim_trailing_whitespace = false

and voila, everything works as intended :)

  • 2
    Good call. I knew it was editorconfig just by reading the title ;-)
    – romainl
    Jul 28, 2016 at 9:28
  • You should accept your own answer.
    – henrebotha
    Feb 5, 2019 at 13:11

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.