Home Download Buy Blog Forum Support

Select All to view invisible characters?

Select All to view invisible characters?

Postby canadaduane on Tue Jan 17, 2012 7:42 pm

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)
canadaduane
 
Posts: 14
Joined: Wed Aug 31, 2011 3:22 pm

Re: Select All to view invisible characters?

Postby C0D312 on Tue Jan 17, 2012 7:48 pm

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: Select all
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)


Add this to your User Keybindings:
Code: Select all
  { "keys": ["escape"], "command": "deselect", "context":
    [
        { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
    ]   
  }
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Select All to view invisible characters?

Postby jps on Wed Jan 18, 2012 12:31 am

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
jps
Site Admin
 
Posts: 3071
Joined: Wed Mar 19, 2008 12:33 pm

Re: Select All to view invisible characters?

Postby C0D312 on Wed Jan 18, 2012 12:39 am

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


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... :)
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Select All to view invisible characters?

Postby canadaduane on Wed Jan 18, 2012 3:13 pm

C0D312 wrote: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:
...


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?
canadaduane
 
Posts: 14
Joined: Wed Aug 31, 2011 3:22 pm

Re: Select All to view invisible characters?

Postby canadaduane on Wed Jan 18, 2012 3:18 pm

canadaduane wrote: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.


This does the trick for me:

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


Thanks again for your help (both!).
canadaduane
 
Posts: 14
Joined: Wed Aug 31, 2011 3:22 pm

Re: Select All to view invisible characters?

Postby pedrober on Wed Jul 11, 2012 8:46 pm

C0D312,
Your initial deselect plugin is perfect. It should be part of the default program configuration. Thank you very much.
pedrober
 
Posts: 40
Joined: Thu Jun 28, 2012 6:21 pm

Re: Select All to view invisible characters?

Postby Deadpool13 on Mon Mar 11, 2013 11:51 pm

C0D312 wrote: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:


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!

canadaduane wrote:This does the trick for me:

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


Also a great idea, but I think I prefer the plugin route. Thanks all!
Nil nisi veritatem video, nil scio, nil studeo. Veritas sum.
Deadpool13
 
Posts: 5
Joined: Wed Mar 06, 2013 6:55 pm


Return to General Discussion

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 18 guests