Reputation: 445
I like to use vim's auto formatting command but it is causing a problem with me and my boss. At some point someone's editor added blank lines with spaces. When i run gg=G
it removes that whitespace and is creating a bunch of noise in my git commits. I still want to be able to format the text but I don't want whitespace removed.
This seems like I need to change a setting somewhere. Any ideas?
Upvotes: 2
Views: 2496
Reputation: 172768
There's no built-in option that you can simply set. The closest is autoformatting; with a
and w
in 'formatoptions'
, Vim will format as you type, and keep a single trailing space at the end of each line belonging to a paragraph. But that doesn't preserve existing trailing whitespace.
If you need to reindent and reformat with gg=G
, that implies that the existing layout is pretty broken. Most people will argue that you shouldn't care about preserving trailing whitespace (itself a bad practice, and usually flagged by Git) in that case.
If you can, limit the scope of the =
command, e.g. by applying it selectively only on few (bad) lines, or the visual selection. That will reduce the noise in commits.
If you really need to reformat while preserving trailing whitespace, I would open a diff inside Vim (using Git, the Fugitive plugin makes this very easy), and then manually edit the trailing spaces back in. The effort required in this should further convince you (and your team) that a bit more care about proper editing hygiene benefits everybody :-)
Upvotes: 1