Sublime Forum

Show/Hide spaces

#1

In order to detect the minimum number of differences between two iterations of a source code file, I am obliged to remove all trailing blanks (or spaces).
(The file will then not be treated as a new one if I introduced by chance a trailing blank at the end of an instruction.)

It would be nice to have the equivalent, at least for spaces, of what we have with Office when we click on the 'Paragraph" sign which represents the functionality “Show or hide formatting marks”.

Office makes the spaces visible by replacing them by a point that is a bit heigher than the point that ends a sentence.

0 Likes

#2

I think this is possible now but only when text is selected. For example, I see the following when selecting text:

The dots are spaces and I believe the horizontal lines are tab characters.

Maybe all that’s needed is a way to toggle these characters on all the time?

0 Likes

#3

There is a setting to control this behavior:

    // Set to "none" to turn off drawing white space, "selection" to draw only the
    // white space within the selection, and "all" to draw all white space
    "draw_white_space": "selection",
3 Likes

#4

Further to what @addons_zz said, if your intention is to see all white space just so that you can remove trailing white space characters, there is also a setting for that; just turn it on and save the file:

// Set to true to removing trailing white space on save
"trim_trailing_white_space_on_save": false,

This is implemented by code in Packages/Default/trim_trailing_white_space.py (visible via PackageResourceViewer) which works by invoking the trim_trailing_white_space command, so if desired you could also bind this to a key or add it to the menu/command palette to trigger it without having to save the file first.

4 Likes

#5

Thank you very much: I had by default:
// Set to “none” to turn off drawing white space, “selection” to draw only the
// white space within the selection, and “all” to draw all white space
“draw_white_space”: “selection”,

but I chose the “all” option and this works very well:
// Set to “none” to turn off drawing white space, “selection” to draw only the
// white space within the selection, and “all” to draw all white space
“draw_white_space”: “all”,

0 Likes

#6

I’m also actively using next simple plugin to toggle whitespaces:

/* 
 * If you use "Vintage" mode. 
 */
  {
    "keys": [",", "w"],
    "command": "toggle_white_space",
    "context": [{"key": "setting.command_mode"}]
  },

/* 
 * If you do not use "Vintage" mode. 
 */
  {
    "keys": ["alt+w"],
    "command": "toggle_white_space"
  },
import sublime
import sublime_plugin


class ToggleWhiteSpaceCommand(sublime_plugin.ApplicationCommand):
    def run(self):
        settings = sublime.load_settings("Preferences.sublime-settings")
        white_space = "selection" if settings.get("draw_white_space", "selection") != "selection" else "all"
        settings.set("draw_white_space", white_space)
        sublime.save_settings("Preferences.sublime-settings")
1 Like