This package creates a prefix key similar to Emacs Auctex. Just press the prefix key followed by keybinding to insert text into the view. E.g. you can press ;
(prefix key) and a
to insert \alpha
. In addition this packages gives you the possibility to insert your own prefix key and keybindings.
Although it is made for LaTeX and focuses on inserting math commands, you can add your prefix key for other languages as well.
Press the prefix key, and a key of the prefix keymap to insert the corresponding command, characters or snippet into the view:
You can press the prefix key followed by ?
to get an overview over all available commands in the prefix keymap:
The prefix keymaps are handled using contexts. Hence you can add keys by defining a keybinding using the corresponding context. The context key for math mode is latex_prefix_key.mode.math
.
An example keybinding to insert \alpha
when pressing a
:
{
"keys": ["a"], "command": "latex_prefix_key_insert", "args": { "characters": "\\alpha" },
"context":
[
{ "key": "selector", "operator": "equal", "operand": "text.tex" },
{ "key": "latex_prefix_key.mode.math" }
]
},
An example keybinding to insert the snippet "\\mathfrak{$1}$0"
when pressing c
and then f
:
{
"keys": ["c", "f"], "command": "latex_prefix_key_insert_snippet", "args": {"contents": "\\mathfrak{$1}$0"},
"context":
[
{ "key": "selector", "operator": "equal", "operand": "text.tex" },
{ "key": "latex_prefix_key.mode.math" }
]
},
If you add an addition keymap for an other prefix mode you can replace math
with the mode name.
Disable the default prefix key:
To disable the default prefix key open the LaTeXMathKeys settings and set the entry disable_default_prefix_key
to true
.
Adding your prefix key:
Add this keybinding to your user keybinding and replace #
with the key you want to use as prefix key:
{
"keys": ["#"], "command": "latex_prefix_key_prefix",
"args": { "insert_prefix": "#", "mode": "math"},
"context":
[
{ "key": "selector", "operator": "equal", "operand": "text.tex" },
{ "key": "latex_prefix_key.math_selector" }
]
},
A prefix key is bound to a so called mode
. Select a mode name for your prefix key, it should be unique and underscore_separated
. If it is prefixed with math
the corresponding keybinding will only applied inside math scopes.
Add the prefix keybinding to your keymap:
{
"keys": ["#"], "command": "latex_prefix_key_prefix",
"args": { "insert_prefix": "#", "mode": "your_mode"},
"context":
[
{ "key": "selector", "operator": "equal", "operand": "text.tex" }
]
},
Add your keybindings with the context key latex_prefix_key.mode.your_mode
:
{
"keys": ["b"], "command": "latex_prefix_key_insert_snippet", "args": { "contents": "\\textbf{$1}$0" },
"context":
[
{ "key": "selector", "operator": "equal", "operand": "text.tex" },
{ "key": "latex_prefix_key.mode.your_mode" }
]
},
If you are used to Auctex, then you feel familiar with the default keybindings. You can see the available keybindings and commands for any prefix keymap by pressing the prefix key (;
) and ?
.
In addition a cheat sheet with the default keys is hosted here: latex_prefix_key_sheet_v0_9.pdf.