helix
                                
                                
                                
                                    helix copied to clipboard
                            
                            
                            
                        Add `trim` to remove trailing whitespace
Resolves #1481
~Currently it doesn't delete empty trailing lines. Is this a desired behavior?~
Currently it doesn't delete empty trailing lines. Is this a desired behavior?
For me yes, but i don't know if others agree
i am not sure if this may be desired, but an option to trim on :write would be decent i guess?
(obv. also :write-quit)
i am not sure if this may be desired, but an option to trim on
:writewould be decent i guess? (obv. also:write-quit)
Someone could follow up on that with a PR. I'm not personally interested in implementing it.
i am not sure if this may be desired, but an option to trim on
:writewould be decent i guess? (obv. also:write-quit)Someone could follow up on that with a PR. I'm not personally interested in implementing it.
I guess this gonna be me then. :) Luckily i get a notification once this PR is merged.
Is this still being worked on? 👀
I'm unsure @koalalorenzo, but as a workaround you can use git-stripspace as a formatter: https://github.com/helix-editor/helix/issues/1481#issuecomment-1421640827
formatter = { command = "git", args = ["stripspace"] }
That will override an existing formatter, but I figure most language formatters (clang-format, gofmt, rustfmt, etc.) will already strip space, so this is mainly needed for filetypes that don't have formatters.
I would eagerly looking forward to a command to trim trailing whitespace (and eventually trim on save as well). Any update on when this will be merged? Thanks!
oh, didn't think of that (I suppose via :pipe cmd?)... what cmd do you use
The "trim final newlines" (:trim lines) option of this somewhat relates to https://github.com/helix-editor/helix/pull/8157 which inserts a final newline if there is none. That is enabled on :w but not :wa, which matches vim.
If this PR gets refactored, enabling "trim trailing whitespace from all lines" (:trim spaces) on :w would likely be a good idea, this would also match vim. :trim lines shouldn't be on by default.
:trim spaces doesn't seem like the most accurate command name, since it doesn't just remove any spaces. Not sure what would be better though: If the full options were named :trim trailing-whitespace and :trim final-newlines that would match vscode (good for discoverability), could have aliases like :trim trailing and :trim lines
Superseded by #8366