Sublime Forum

Defining a key

#1

A trivial question. I am totally new to Sublime Text and I am setting it up to my preferences. But, I need some help.
I want to redefine a key combination such that when I press the right keys (ex: alt-a) I get text that I want (ex: alert(“got to here”);. I got that far using macro define. But I have two problems. First, I don’t want to press the 3 keys I need to press to get the macro to run. Second, apparently I can only have 1 active macro. But I want to define other macros (ex: alt-b types the text "alert();
I know its simple but I am confused with the Sublime way of doing things (key-bindings, Json, macros, autofill…).
Help

0 Likes

#2

Command palette -> Preferences: Key Bindings

On the left column are the built-in key bindings and on the right column are your user key bindings. User key bindings take precedence over the built-ins.

For your simple examples you don’t need to create a macro, you can just use the insert or insert_snippet commands, like this:

[
    {
        "keys": ["alt+a"],
        "command": "insert",
        "args": {"characters": "alert(\"got to here\");"}
    },
    {
        "keys": ["alt+b"],
        "command": "insert_snippet",
        "args": {"contents": "alert($0);"}
    },
]

If you want to do more complex things using macros, search for the run_macro_file command in the left column for examples.

https://www.sublimetext.com/docs/key_bindings.html

1 Like