Sublime Forum

Keyboard shortcut regex'es

#1

Hi

I’m trying to bind ‘#’ to the snippet ’ # $0’ when:

  1. I’m editing Python code
  2. The cursor is at the end of a line
  3. The cursor is not at the start of a line (including empty lines)

The code below works, except for the requirement 3. Any suggestions on how to make it work? My attempt is the commentet out line.

I’ve tried adding the following colde to mey user keyboard settings:

{ "keys": "#"], "command": "insert_snippet", "args": {"contents": " # $0"}, "context": { "operator": "equal", "operand": "source.python", "key": "selector" }, { "match_all": true, "operator": "equal", "operand": true, "key": "selection_empty" }, { "key": "following_text", "operator": "regex_match", "operand": "$", "match_all": true }, // { "key": "preceding_text", "operator": "regex_match", "operand": "^", "match_all": false } ] },

0 Likes

#2

You were kinda close. The correct syntax is:

{ "key": "preceding_text", "operator": "not_regex_match", "operand": "^", "match_all": true },

Hope this helps,
Alex

0 Likes