Home Download Buy Blog Forum Support

alternate key bindings

alternate key bindings

Postby vim on Wed Jan 14, 2009 6:52 am

i would have like to be able to switch between alternate key bindings.

it could simplify many key binding i use a lot.

it would be super-cool if i could bind this switch to the caps-lock(override the upper case it implies). so when it is ON i can see i am in another key binding, etc.
Posts: 298
Joined: Tue May 27, 2008 6:51 pm

Re: alternate key bindings

Postby vim on Sat Jan 31, 2009 10:18 am

i am aiming toward a vim like key binding, not as the default replacement, just as an alternate keymap. let me explain a bit, so you won't think i am forcing going into something just to imitate an old editor.

the extensive customization could be made on sublime, requires more and more keybinding, i am just tired to flex my fingers from the ctrl, alt and other combinations everytime. so i thought the vim way to deal with it isn't quit bad. a simple overview on this vim feature: on the vim editor, you can select to go-out of editing mode, into a control mode, in which keys you press are not necessarily typed into screen, but rather are used as controls. so, on control mode, instead of pressing ctrl+f to search you use just the key '/'. if we use if for sublime we can set that instead of ctrl+shift+o to search through all opened files, use just the key 'o' for instance.

so i got this far, first a plugin to easily switch between keymaps:
Code: Select all
import sublime, sublimeplugin

class ToggleKeymapCommand(sublimeplugin.TextCommand):
    def run(self, view, args):
        mode = args[0]
        print mode
        print "switching to " + str(mode) + " keymap"
        sublime.options().set('keymap', mode)

    def isEnabled(self, view, args):
        return True

second, under User/Default.sublime-keymap, add:
Code: Select all
<binding key="f12" command="toggleKeymap Vim"/>

and last, create User/Vim.sublime-keymap, and just copy into it all the Default keymap (from Default/Default.sublime-keymap), adding the following line:
Code: Select all
<binding key="f12" command="toggleKeymap Default"/>

now you can play with it. go to User/Vim.sublime-keymap, adding
Code: Select all
<binding key="/" command="showPanel find"/>
to search with '/'. or replace the following:
Code: Select all
<binding key="alt+f3" command="findAllUnder"/>
Code: Select all
<binding key="*" command="findAllUnder"/>

so far so good, but here are the problems:
1. i would like to use capslock as toggle key, so i can see the key light on my keyboard to show me on which mode i am, i tried it, and i can do it, but afterward, all the keys i press are on upper case (surprise, surprise...) it would be nice to override it, somehow.
2. on vim, you can concatenate control keys on the control mode, so you can use not just 'o' to to open file, for example, but also 'ot' for open file in tab, 'od' for open file in directory, etc. on sublime i can concatenate only ctrl/alt/shift and one more normal key. i would like to be able to do it for any number of normal keys (you can think of it like the snippet mechanism)
3. it has its glitches, so i bind the key '*' to search-all-under (like alt+f3), it works, but, oops, it works also when i start to type the search terms, so if i try to use '*' i get the effect of search-all-under again... i thought of using <context name=..." value="..."/> somehow, but i dont know if there is one for checking if the focus is on the main window or not...

any way, feel free to comment, etc.

happy subliming :)
Posts: 298
Joined: Tue May 27, 2008 6:51 pm

Return to Ideas and Feature Requests

Who is online

Users browsing this forum: No registered users and 7 guests