helix icon indicating copy to clipboard operation
helix copied to clipboard

Add `trim` to remove trailing whitespace

Open kirawi opened this issue 3 years ago • 2 comments

Resolves #1481

~Currently it doesn't delete empty trailing lines. Is this a desired behavior?~

kirawi avatar Sep 03 '22 22:09 kirawi

Currently it doesn't delete empty trailing lines. Is this a desired behavior?

For me yes, but i don't know if others agree

poliorcetics avatar Sep 04 '22 15:09 poliorcetics

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)

SoraTenshi avatar Oct 27 '22 15:10 SoraTenshi

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)

Someone could follow up on that with a PR. I'm not personally interested in implementing it.

kirawi avatar Nov 23 '22 02:11 kirawi

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)

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.

SoraTenshi avatar Nov 23 '22 13:11 SoraTenshi

Is this still being worked on? 👀

koalalorenzo avatar Apr 12 '23 12:04 koalalorenzo

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.

rcorre avatar Apr 12 '23 17:04 rcorre

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!

Joe-Zer0 avatar Aug 16 '23 15:08 Joe-Zer0

oh, didn't think of that (I suppose via :pipe cmd?)... what cmd do you use

tshepang avatar Aug 16 '23 15:08 tshepang

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

tgross35 avatar Sep 12 '23 21:09 tgross35

Superseded by #8366

kirawi avatar Sep 24 '23 01:09 kirawi