trim.nvim
trim.nvim copied to clipboard
Add trim of changed lines only
Closes #22.
Adds the config option trim_changed_only
(default false
).
I think this is a relatively neat fix that even retains leading lines and trailing lines trimming for only changed lines. I have to admit I didn't do much more than translate the general solution approach that vim-better-whitespace
uses here to figure out the changed blocks, except that this version even ensures the line breaks conform to fileformat
(otherwise diff may falsely report the entire file is changed).
For this to work, diff
must be on the PATH
, and if it isn't, you get a complaint and trimming deactivates entirely.
Note that in principle the regexes used for trimming should still be updated to work with all the other line endings for true compatibility. It would amount to replacing \n
with \(\r\n\|\r\|\n\)
in the trailing and leading lines trimming regexes.
Although I've been dogfooding this for a little bit, this is the first time I'm messing with Lua, so please give it some close scrutiny. It's quite possible there are some functionality or perf corner cases with the functions I'm using that I'm not aware of.