22 votes
 
Is there a way to tell Sublime Text to display all Characters?

In Notepad++, clicking View > Show Symbol > Show All Characters produces the following:
  • Spaces are materialized with dots
  • TABs are materialized with right arrows
  • CR/LFs are displayed with CR/LF icons 
  • Probably more cases that I'm not aware of

Mandatory screenshot:


Is there a way to replicate this behavior? I am currently working with big painful CSV files (Excel or CSVEasy are not options), and seeing all the characters is invaluable here.


Thanks for your help.

 
+2
kutu

Only for spaces (as dots) and tabs (as horizontal line)

Preferences -> Settings - User
"draw_white_space": "all",
Translation provided by Microsoft translator:

 
0
ronj
Exactly what I need! That works, thank you :)


Additional nugget: how can I bind toggling draw_white_space to a shortcut? Using some examples, I tried adding the following line to my keymap, but it doesn't toggle, it just toggles once, but re-pressing the shortcut doesn't produce anything:

{ "keys": ["alt+d"], "command": "toggle_setting", "args": {"setting": "draw_white_space"} },

Maybe I should specify to the toggle_setting commang the values to toggle between? But how can I do that? Also, how did you find the existence of the draw_white_space command? And how can I find the values accepted by the command?

Thanks for the help!

Translation provided by Microsoft translator:

 
+2
kutu
{ "keys": ["shift+alt+d"], "command": "set_setting", "args":
{
"setting": "draw_white_space",
"value": "all"
}
},
{ "keys": ["shift+alt+a"], "command": "set_setting", "args":
{
"setting": "draw_white_space",
"value": "selection"
}
},
Also, how did you find the existence of the draw_white_space command?
reading Preferences -> Settings - Default
And how can I find the values accepted by the command? 

explore KeyBindings file, or try to find command source code in ST2 Packages in *.py files

also try to write Sublim plugin, and you will learn more about ST2

Translation provided by Microsoft translator:

 
+9
FichteFoll

The solved problem aside, I'd really like to "see" the line ending characters in some cases.

Translation provided by Microsoft translator:

 
0
Roger Sperberg

And I, among the small number of people working in languages that don't put spaces between words, would like to be able to see the zero-width space (aka ZWSP), Unicode U+200B.

Translation provided by Microsoft translator:

 
0
FichteFoll
import sublime_plugin


class ShowZeroWidthSpace(sublime_plugin.EventListener):
  def on_modified(self, view):
  spaces = []
  p = 0
  while 1:
  s = view.find(u'\u200b', p + 1)
  if not s:
  break
  spaces.append(s)
  p = s.a

  if spaces:
  view.add_regions("zero-width", spaces, "string")
  else:
  view.erase_regions("zero-width")

Should work well enough. No feature to disable so be careful with editing large files (with many zero-width whitespaces).
Translation provided by Microsoft translator:

 
0
Roger Sperberg

@FichteFoll,


I'm not sure how this works — is it actually inserting a regular space when it finds a ZWSP?


Thanks for providing this!

Translation provided by Microsoft translator:

 
0
FichteFoll

No, it just marks ZWSP characters with add_regions. Precisely, it paints their backgrounds but since they have zero width it just inserts a line in your string color. Just make sure that you fix the indentation and unindent after "break" because userecho messed up indentation and this is crutial with Python.

Translation provided by Microsoft translator:

 
+1
Roger Sperberg
I've tried every sort of interpretation for the indenting, but I can't seem to get this to work.

Could you perhaps re-enter the script with "b" indicating a blank space (or something like that) to indicate the correct indentation?

Is "sublime_plugin" supposed to be one word without an underscore?


Translation provided by Microsoft translator:

 
0
Roger Sperberg
The console's messages have guided me somewhat — I see that "sublime_plugin" should have an underscore, for one thing.

This script is being loaded, but I don't see any visible indication of a ZWSP. (I haven't checked this in an encompassing variety of circumstances, however.) Just now I'm wondering if using a black background might be hiding this background line.

And, in checking this, I find making a modification to the file causes ST2 to freeze. So I think that (a) I'm on the track and (b) I haven't got the indenting right. However, at least I'm not getting an error message from the console about the indenting.


Translation provided by Microsoft translator:

 
0
Roger Sperberg
Success!

I altered the indention of two lines, saw that see-zwsp loaded OK, then made a change to the file with Khmer text (and ZWSP's). And they became visible.

Thanks very much for this. You're a true philosopher, @FichteFoll!


Translation provided by Microsoft translator:

 
0
FichteFoll

Version without the indentation messed up: https://pastebin.com/ehWxNfMe

Translation provided by Microsoft translator:

 
+3
robertcollier4

I would like to recommend adding showing the CR and LF line-ending characters as well with draw_white_space. Or add a new setting for draw_white_space_lineendings.


Although you can choose your line-endings type you want in the Menu - it is nice to be able to see it quickly visually - or to see if a file may be using mixed line-ending types.

Translation provided by Microsoft translator:

 
0
Ned Martin

I agree with this, it would be a nice feature.

Translation provided by Microsoft translator:

Community stats

  • 27,555People
  • 3,826Feedback
  • 5,695Comments
  • 64,471Votes