Search code examples
rsublimetext3key-bindingssublimetext4

How to assign a string to a keybinding in Sublime Text 4?


Is there a way to print something with the given keybinding in Sublime Text 4?

E. g. for the sake of R, I would like the alt+oem_minus and alt+- keybindings strokes to result in <-.

I understand that for whatever I want to do, I can record a macro and this would work just fine but this action is so trivial that I wonder whether I can do without macro.

I understand that there are probably language plugins and IDEs that include this feature by default, but the most apparent one, the R-IDE, doesn't seem to have it, and moreover, Sublime is just an editor for quick scripts, not a comprehensive IDE, I have to intention to aggravate the app with scripts I do not need.

Thank you in advance for any response!


Solution

  • Open Sublime Text, go to Preferences > Key Bindings and add this:

    [
        {
            "keys": ["alt+keypad_minus", "alt+-"],
            "command": "insert_snippet",
            "args": {"contents": "<-"}
        }
    ]
    

    If you want to position the cursor after <-, you can do it via $0 like this:

    "args": {"contents": "<- $0"}