helix icon indicating copy to clipboard operation
helix copied to clipboard

It would be nice to have a `trailing` option for rendering spaces and tabs

Open dimus opened this issue 2 years ago • 20 comments

Describe your feature request

Additional setting for [editor.whitespace.render]

Currently spaces and tabs have 2 possible settings in config: space = "none" or space = "all" and tab = "none" or tab = "all". I think it woud be beneficial also to have a setting space = "trailing" and tab = "trailing" to visualize only trailing white spaces/tabs

dimus avatar Jun 08 '22 19:06 dimus

If this was to be added, I think it would also be useful to have a "leading" option for people who use leading whitespace to keep track of which level of indentation they're in.

cinerea0 avatar Jun 08 '22 20:06 cinerea0

Also perhaps a specifier at the [editor.whitespace.render] level for these options:

[editor.whitespace]
render = "trailing"
# render = "leading"

n0s4 avatar Jun 08 '22 20:06 n0s4

If this was to be added, I think it would also be useful to have a "leading" option for people who use leading whitespace to keep track of which level of indentation they're in.

how to deal with different cardinality of settngs in this case? all and none can happen only by themselves leading and trailing can happen by themselves, or in tandem, but cannot be combined with all and none?

dimus avatar Jun 08 '22 20:06 dimus

Indent guides https://github.com/helix-editor/helix/pull/1796 are probably more appropriate for tracking indentation levels than visible whitespace

the-mikedavis avatar Jun 08 '22 20:06 the-mikedavis

Also, it would be great if the theme could have different colors for trailing and leading whitespace. For example a faded color for leading and strong for trailing.

bjorn-ove avatar Jun 08 '22 20:06 bjorn-ove

I think this can be solved with theming rather than adding options to render only leading/trailing whitespace. Trailing whitespace could be themed ui.virtual.whitespace.trailing for example and this could be set to something noticeable on a per-theme basis. With this approach you could view leading/trailing whitespace without having visible whitespace turned on.

the-mikedavis avatar Jun 08 '22 22:06 the-mikedavis

I do like the idea of theming, howerver would also be great to be able to toggle this setting when trailing/leading spaces mean something different, like in CSV files, or because of a user preference.

dimus avatar Jun 09 '22 09:06 dimus

as @archseer mentioned in chat:

this would add some overhead to the rendering since you'd need to track exactly where the last non-whitespace char is to determine if a space is trailing or not

Would toggle help here as well? So for people who do not need the feature, or who disabled it for a time-being it does not slow down the performance, and for people who need it, it is available.

dimus avatar Jun 09 '22 13:06 dimus

Indent guides are one thing, but they don't help to spot mixed indentation. If I have listchars set reasonably in Vim, a line starting with spaces looks differently than one starting with tabs, and it should be, as spaces have no place in indentation for me.

Additionally, I'd like to have characters for precedes/extends (parts of the line hidden when it's too long), multispace (more than one space after the other) and EOL. Well, basically, I'd like to have everything I can do with listchars in Vim 🤷‍♂️

diktomat avatar Jul 07 '22 11:07 diktomat

Hi, indeed being able to visualize trailing spaces would be awesome.

mpizenberg avatar Jul 07 '22 21:07 mpizenberg

Just a heads-up, I opened a PR some time ago, it implements trailing whitespace in an efficient way. Here's the PR: https://github.com/helix-editor/helix/pull/4306 I've been using it since then without a problem.

alevinval avatar Jan 10 '23 11:01 alevinval

I think this can be solved with theming rather than adding options to render only leading/trailing whitespace

this seems to make sense for the different "weighting" that other ppl suggested - having different weights by default seems overkill...

goyalyashpal avatar Feb 19 '23 11:02 goyalyashpal

I also like the idea of having leading whitespace rendered if it is less spaces than the indentation of the file.

For example, if your indentations are at 4 spaces, and you start writing a line which has 3 spaces only, then they are rendered. Or if you have a new line with 6 spaces, then one indentation guide is rendered, and the remaining 2 spaces are rendered.

tqwewe avatar May 03 '23 07:05 tqwewe

"Trailing" in the title brought in discussion of "leading", and now my request has to do with "in the middle", though I wonder if I should start an entirely new issue for it or not. It would also be nice to be able to configure to only render spaces in the middle of a line if there are more than one consecutive space. e.g. VSCode allows it, and its capability was mentioned in a request for similar capability in vim: https://stackoverflow.com/questions/58152552/render-space-if-it-have-multi-space-in-vim For me, it is helpful to visually see that there are unnecessary, (typically accidental) extra spaces in the middle of a line. (edit addition --> ...without the overbearing dot for the [usually correct, single] space between every word.)

feinedsquirrel avatar May 28 '23 05:05 feinedsquirrel

This issue overlaps with https://github.com/helix-editor/helix/issues/1068

chtenb avatar Aug 27 '23 07:08 chtenb

Indent guides #1796 are probably more appropriate for tracking indentation levels than visible whitespace

Perhaps some people prefer it. Leading, trailing, and non-single space visualization are useful and nice-to-haves to some people.

Because of the unexpected way, yes the expected way is VS Code and Vim, indent guides and whitespace are handled, I use tab characters with a bar to identify if a space is mixed in.

[editor.whitespace.render]
nbsp = 'all'
tab = 'all'
# space = 'all'

[editor.whitespace.characters]
space = '·'
tab = '│'
# tabpad = '→'

Another option is using indent guides with tabs hidden and showing all space characters.

tabpad also has unexpected behavior, more to do with how indents are handled by lsp config.

Edit: this bar character is thin and center aligned

carlosvigil avatar Nov 21 '23 00:11 carlosvigil

Showing trailing spaces would be nice!

patrickelectric avatar Jun 15 '24 09:06 patrickelectric

Did anything ever come of this? I would like to be able to show leading and trailing whitespace also

blex-max avatar Jun 19 '24 16:06 blex-max

There is an open PR for this: https://github.com/helix-editor/helix/pull/7215 You can merge it in your own fork and compile from source if you're interested in this feature.

chtenb avatar Jun 19 '24 17:06 chtenb

That PR appears to be for trailing whitespace - I'm mostly interested in leading!

blex-max avatar Jun 20 '24 08:06 blex-max