C
C
creatoroftheworld2016-03-10 15:08:12
Python
creatoroftheworld, 2016-03-10 15:08:12

How to bind different commands to a hotkey depending on the syntax?

In my case, it is necessary that if I press ctrl + q in the js file, then the console.log macro is executed, and in another type of document, something else happens

{ 
    "keys": ["ctrl+q"],
    "command": "run_macro_file",
    "args": {"file": "Packages/User/console.sublime-macro", 
    "syntax": "Packages/HTML/HTML.sublime-settings",  // * ???
  }

Google says you need this, but there is no such file

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ruchkin, 2016-03-10
@VoidEx

args are command arguments and you need context
sublimetext.info/docs/en/reference/key_bindings.html
https://forum.sublimetext.com/t/per-syntax-key-bin...
Specifically selector is scope , which just defines the language
Here is an example for HTML:

{
  "keys": ["ctrl+shift+enter"], 
  "command": "insert_snippet",
  "args" : {
    "contents": "<br/>"
  },
  "context": [
    { "key": "selector", "operator": "equal", "operand": "text.html" }
  ]
},

I don't know what kind of scope JS has.
Probably something like text.javascript or text.js
I checked such a keymap in the user's `Default (Windows).sublime-keymap`:
[
  {
    "keys": ["ctrl+k", "alt+k"],
    "command": "set_layout",
    "args":
    {
      "cols": [0.0, 1.0],
      "rows": [0.0, 1.0],
      "cells": 
    },
    "context": [
      { "key": "selector", "operator": "equal", "operand": "source.c++" }
    ]
  }
]

Exposed Haskell syntax - doesn't work
Exposed C++ - works

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question