Home Download Buy Blog Forum Support

[solved] Regex scope

[solved] Regex scope

Postby zloutenka on Sat May 18, 2013 6:00 pm

Is it possible to bind a key based on regex?

I need to bind <tab> to a macro in case I have a cursor
Code: Select all
\uv{somewhere_in_here}
. There's no specific language scope inside :(
Last edited by zloutenka on Sat May 18, 2013 7:08 pm, edited 1 time in total.
zloutenka
 
Posts: 13
Joined: Mon May 07, 2012 12:44 pm

Re: Regex scope

Postby skuroda on Sat May 18, 2013 6:20 pm

You can use the preceding_text and following_text context operands. You would likely use it in combination with regex_match context operator.

See http://docs.sublimetext.info/en/latest/ ... -a-context for more information on context
skuroda
 
Posts: 683
Joined: Fri Oct 05, 2012 8:11 am

Re: Regex scope

Postby zloutenka on Sat May 18, 2013 6:58 pm

Thanks, that works!

Code for future readers:
Code: Select all
  // tab out of \uv{}
  { "keys": ["tab"],
    "command": "run_macro_file", "args": {"file": "Packages/User/Macros/moveOutOfBracket.sublime-macro"},
    "context": [
      { "key": "selector", "operator": "equal", "operand": "text.tex" },
      { "key": "preceding_text", "operator": "regex_contains", "operand": "uv\\{.*", "match_all": true },
      { "key": "following_text", "operator": "regex_match", "operand": ".*\\}", "match_all": true }
    ]
  },
  // tab out of \uv{}
  { "keys": ["tab"],
    "command": "move", "args": {"by": "characters", "forward": true},
    "context": [
      { "key": "selector", "operator": "equal", "operand": "text.tex" },
      { "key": "preceding_text", "operator": "regex_contains", "operand": "uv\\{.*", "match_all": true },
      { "key": "following_text", "operator": "regex_match", "operand": "\\}", "match_all": true }
    ]
  },
zloutenka
 
Posts: 13
Joined: Mon May 07, 2012 12:44 pm


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 17 guests