2

In Sublime Text 2, some of my whitespace behaves strangely.

For example, I select the contents of a script (as shown in the screenshot below), and do Shift + Tab (to reduce indentation) it only works on the lines with normal spacing, resulting in my code indentation becoming all wonky.

Notes:

  • the non-space white spaces are not tabs,
  • it's set to indent using spaces
  • doing "convert tabs to spaces" has no effect.
  • My settings file has: "draw_white_space": "all",

I think this only happens with code pasted from elsewhere (like OneNote), and the only way I've found to deal with it is to manually replace the spacing with actual spaces.

What is the explanation for this behavior? Or is there a way to better deal with it?

Weird whitespace

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Zach Lysobey
  • 14,959
  • 20
  • 95
  • 149
  • And you believe it's not some sort of UTF-8-ish characters that aren't counted (by default) as whitespace? – Dave Newton May 15 '13 at 20:56
  • Not really sure I guesse. I save as UTF-8, and they still display as pictured above. – Zach Lysobey May 15 '13 at 20:57
  • 2
    That would preserve any non-ASCII-ish stuff: look at it with a hex dump and see what's actually there. – Dave Newton May 15 '13 at 20:58
  • Hmm, not sure how to do a hex dump, but I think I did soemthign vaguely equivalent (pasted as HTML to browser with a plugin). It looks like the renegade spaces are actually ` `'s (or non-breaking spaces) – Zach Lysobey May 15 '13 at 21:20
  • not sure why I didn't think of it before, but I just did a find replace (selected a nbsp and did ctrl+h) with a regular space. IDK if there's a better way to go about it, but that seems reasonably easy. – Zach Lysobey May 15 '13 at 21:22
  • Don't know what else you'd do, although I suspect you could customize what's considered whitespace. IMO it's better to replace it anyway. Also, that's a danger of pasting anything from non-text sources. – Dave Newton May 15 '13 at 21:27
  • Thanks for all your help Dave. If you want a checkmark and some nerd-points, feel free to write up an answer. – Zach Lysobey May 15 '13 at 21:28
  • 1
    Without posting the source code it is difficult to diagnose exactly. Some candidates are U+00A0 ([NO-BREAK SPACE](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=156&number=128)), U+2009 ([THIN SPACE](https://www.charset.org/utf-8/9)), U+200B ([ZERO WIDTH SPACE](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8192&number=128)), U+200C ([ZERO WIDTH NON-JOINER](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8704&number=128)), and U+FEFF ([ZERO WIDTH NO-BREAK SPACE](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=65272&number=128)) – Peter Mortensen May 01 '23 at 22:22

1 Answers1

3

I'd assume they're something non-ASCII-ish that looks like whitespace, but actually isn't.

When I have files like this I generally hex dump them from the command line, or you can install a Sublime hex editor like HexViewer via normal package management that lets you do some fun stuff.

Once you know what the offending character(s) are you can use regular search-and-replace to make them be actual spaces, tabs, or whatever seems appropriate.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • [*from comments above*] It looks like the renegade spaces are actually ` `'s (non-breaking spaces). A find-replace cleared it right up. Thanks Dave! – Zach Lysobey May 15 '13 at 22:36
  • @ZachLysobey, I am curious how do you replace non-breaking space with normal space in sublime text. – jdhao Dec 12 '17 at 01:29
  • @jdhao I just cut-and-pasted the non-breaking space into the *find* field, and typed a normal space into the *replace*. You can probably also do this with regex find-replace using unicode code-point matching (https://www.regular-expressions.info/unicode.html) – Zach Lysobey Dec 12 '17 at 22:17
  • 2
    I am able to find the `no-break space` using `\x{a0}` and replace it with normal space, thanks. – jdhao Dec 13 '17 at 01:29