Sublime Forum

Select All to view invisible characters?

#1

I enjoy the aesthetic style that Sublime Text has. Specifically, invisible characters (e.g. tab, space, line feed) are kept invisible unless you need to know about them.

Currently, when I need to know about them, I use “Select All” (command+A on the Mac). This is great, except that restoring the state after a Select All requires me to use the mouse to click on the location the caret used to be (i.e. this deselects all text and places the caret under the mouse cursor).

Is there a better way to do this? My natural reaction when I Select All and want to restore the state is to press ESC. If there is no meaning associated with ESC when text is selected, how might I go about restoring the caret and deselecting text? Is this something I could do programmatically? Or a new feature request?

Thanks,
Duane Johnson
(canadaduane)

0 Likes

#2

I found this very silly too. There is no deselect command. So I made a plugin that deselects. I set the plugin to work when there is text selected, if I press enter, it deselects. This made sense for me because when I have text selected, I never need to press enter anyway. Though you can set it to esc. Here’s the plugin:

[code]import sublime, sublime_plugin

class DeselectCommand(sublime_plugin.TextCommand):
def run(self, edit):
end = self.view.sel()[0].b
pt = sublime.Region(end, end)
self.view.sel().clear()
self.view.sel().add(pt)[/code]

Add this to your User Keybindings: [code] { “keys”: “escape”], “command”: “deselect”, “context”:

    { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
]   

}[/code]

0 Likes

#3

Command+U (or Edit/Undo Selection) will undo the Select All and return you to the previous state.

COD312: Another way to shrink a selection down to one end or the other is to press the left or right arrow key

0 Likes

#4

Thanks, but I find that using enter is faster because I use incremental find to navigate to editor, so when got to where I want, I don’t want to move my hand to the arrow keys… :smile:

0 Likes

#5

[quote=“C0D312”]I found this very silly too. There is no deselect command. So I made a plugin that deselects. I set the plugin to work when there is text selected, if I press enter, it deselects. This made sense for me because when I have text selected, I never need to press enter anyway. Though you can set it to esc. Here’s the plugin:

[/quote]

This is really great! Thank you.

I wonder if it’s possible to combine both your plugin and the Command+U technique, so that we can rebind “escape” (or “enter”) to “Undo Selection” (Command+U) in the context of Select All? In other words, maybe a plugin isn’t necessary–just a keybinding. What do you think?

0 Likes

#6

[quote=“canadaduane”]
I wonder if it’s possible to combine both your plugin and the Command+U technique, so that we can rebind “escape” (or “enter”) to “Undo Selection” (Command+U) in the context of Select All? In other words, maybe a plugin isn’t necessary–just a keybinding.[/quote]

This does the trick for me:

	{ "keys": "escape"], "command": "soft_undo", "context":
		
			{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
		]
	}

Thanks again for your help (both!).

0 Likes

#7

C0D312,
Your initial deselect plugin is perfect. It should be part of the default program configuration. Thank you very much.

0 Likes

#8

I was having a huge issue with not having a deselect hotkey as well, I don’t mind clicking off the selection when it’s small but having to go through the menu to do a soft undo after using select all is a pain. The deselect plugin is perfect using the Esc key, much appreciated!

[quote=“canadaduane”]This does the trick for me:

[code]
{ “keys”: “escape”], “command”: “soft_undo”, “context”:

		{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
	]
}

[/code][/quote]

Also a great idea, but I think I prefer the plugin route. Thanks all!

0 Likes

#9

I had a bit of trouble because the binding would conflict with Escape hiding the search panel. That is fixed with the following binding:

  {
   "keys": ["escape"],
   "command": "deselect",
   "context": [
      {
       "key": "selection_empty",
       "operator": "equal",
       "operand": false,
       "match_all": true
      },
      { "key": "panel_visible", "operator": "equal", "operand": false }
    ]
  },
1 Like

#10

Just as an additional note, the draw_white_space setting can be set to all instead of selection to render white space even if there is not a selection.

This sample plugin contains a command that would allow you to easily toggle that setting back and forth between selection and all; there are several examples in comments at the top of the code and this is one of them.

Something like this lets you perform the operation with only a single keystroke instead of having to first select everything and then remove the selection later and may or may not be useful for other settings as well.

0 Likes