Home Download Buy Blog Forum Support

command_mode key bind

command_mode key bind

Postby ldap on Thu May 05, 2011 2:19 pm

How do I bind a key combo to command_mode?

Code: Select all
{ "keys": ["alt+z"], "command": "setting", "args": {"command_mode": true} }
ldap
 
Posts: 6
Joined: Thu May 05, 2011 2:12 pm

Re: command_mode key bind

Postby guillermooo on Thu May 05, 2011 3:28 pm

You use a context:

Code: Select all
   { "keys": ["alt+z"], "command": "reindent", "context":
      [
         { "key": "setting.command_mode", "operator": "equal", "operand": true }
      ]
   }


Of course, for this to ever work, you need to set command_mode to true first.
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: command_mode key bind

Postby ldap on Thu May 05, 2011 11:30 pm

Thats what im trying to work out... how do i turn command_mode on? with out doing it via the console whats the key combo... and can i bind one?
ldap
 
Posts: 6
Joined: Thu May 05, 2011 2:12 pm

Re: command_mode key bind

Postby guillermooo on Fri May 06, 2011 5:10 am

Oh... There used to be a "set" command in Sublime 1. I'm not sure whether it's in for Sublime 2 yet, but I can't find it. Short of writing a plugin for it, I don't see any other way.

Plugin:

Code: Select all
import sublime, sublime_plugin

class ToggleCommandModeCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        status = bool(self.view.settings().get('command_mode'))
        self.view.settings().set('command_mode', not status)



In a .sublime-keymap:

Code: Select all
[
   {
      "keys": ["j", "j"],
      "command": "toggle_command_mode"
   }
]
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: command_mode key bind

Postby ldap on Fri May 06, 2011 6:24 am

Thank you very much that worked very well!

Now to bind some keys to command mode?
has any one built VIM like key bindings?
ldap
 
Posts: 6
Joined: Thu May 05, 2011 2:12 pm

Re: command_mode key bind

Postby ldap on Mon May 09, 2011 11:41 am

Code: Select all
{ "keys": ["d"], "command": "left_delete", "context":[{ "key": "setting.command_mode", "operator": "equal", "operand": true }] },
{ "keys": ["d", "d"], "command": "run_macro_file", "args": {"file": "Packages/Default/Delete Line.sublime-macro"}, "context":[{ "key": "setting.command_mode", "operator": "equal", "operand": true }] }


Why does the second "d", "d" wipe out the first or make it behave odd?
ldap
 
Posts: 6
Joined: Thu May 05, 2011 2:12 pm

Re: command_mode key bind

Postby guillermooo on Mon May 09, 2011 12:06 pm

I believe Sublime resolves ambiguous key bindings with a timeout, so that d will presumable trigger only after a short while (so Sublime knows you didn't mean d,d).
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: command_mode key bind

Postby ldap on Mon May 09, 2011 12:33 pm

ok... im trying to make it work like vims key binds. Can you set how long the time out should wait?
ldap
 
Posts: 6
Joined: Thu May 05, 2011 2:12 pm

Re: command_mode key bind

Postby guillermooo on Mon May 09, 2011 12:59 pm

Not feasible right now, as far as I know. I hope a more powerful keybindings system will be added in the future, though.

But you could approach this differently if you're willing to put up with some frustration:

Forget about command mode and open an input_panel instead. Type the command there and parse that. I won't work well for motions, and it's far from ideal, but it's something at least.

On the other hand, simple motions should work well with the existing support for command mode. hjkl, HJKL, b, e, a, E, A, o, O, G, gg, etc...
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: command_mode key bind

Postby ldap on Mon May 09, 2011 1:08 pm

Ok thanks, yeah would be cool if it could copy Vims edit mode.

But command mode is cool might make up some short cuts to go in there see how it goes
ldap
 
Posts: 6
Joined: Thu May 05, 2011 2:12 pm

Next

Return to Technical Support

Who is online

Users browsing this forum: No registered users and 25 guests