Sublime Forum

Disable keybinding when inside a specific LaTeX environment

#1

I am trying to create a key binding that will help Git work better with LaTeX files. The goal is to have my TeX files have one sentence of text per line. (The simplest version would be to get used to manually inserting a line break after each period, but I do not want this to become a habit when I’m not using TeX.)

The current plan is to have the space character bound to a simple command so that

 Hello world. |

will result in

[code]Hello world. %
|[/code]

(I’m using ‘|’ to represent the position of the cursor.)

So far, this is what I have, which seems to work just fine:

{ "keys": " "],
		"context":  
				{"key": "selector", "operator": "equal", "operand": "text.tex.latex"},
				{"key": "preceding_text", "operator": "regex_match", "operand": "(^.+\\.$)|(^.+\\?$)|(^.+\\.+\\)$)"}
				],
		"command": "insert", "args": {"characters": " %\n"}
}

The problem is that I do not want this functionality when I’m using TikZ. So I’m looking for a way of restricting this functionality to when I’m not inside a ‘tikzpicture’ environment. Thoughts?

0 Likes

#2

I don’t know the scopes of tikz but you can inspect that via ctrl +alt+shift +p and then exclude it from the selector by prepending a hyphen.

0 Likes

#3

Thanks. What I get inside a tikzpicture environment is this: text.tex.latex meta.function.environment.general.latex

That seems to be the same scope for pretty much any other environment. Is there a way to define new scopes? (I’m hoping that question makes sense.)

0 Likes

#4

Yeah, that is pretty generic. You’ll need to edit the syntax definition to add an explicit match for the tikzpicture environment.

0 Likes

#5

Alright, I’ll have a look. Thanks again.

0 Likes