In Texmaker one can select a text, that should be emphasized and press CTRL+B to wrap the text portion with \textbf{%TEXT%}.
CTRL+B is probably already in use, but one could certainly use other combinations.
Would be great if one could select a text (%TEXT%) and press
You can use Visual Studio Codes internal keybindings.json for this, here is an example:
{
"key": "ctrl+shift+B",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "\\textbf{${TM_SELECTED_TEXT}}$0"
}
},
{
"key": "ctrl+shift+I",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus && editorLangId == latex", // chained clause
"args": {
"snippet": "\\textit{${TM_SELECTED_TEXT}}$0"
}
}
key clause declares which key should be pressed to trigger from the accepted keys.command clause let's vscode know that this is a snippet insert command read more here.when clause let's vscode know what context it is used in, as described here&& in for instance the when clause, see example above._args.snippet ${TM_SELECTED_TEXT} wraps around as you asked. you can see possible variables here.$0 sets position of cursor after command has triggered.Great! Worked instantly. Thanks a lot. :blush:
Is there a way to activate those keybindings only for certain file extensions (e.g. tex)? :thinking:
Yes, by using multi-clause in when clause.
Like this: "when": "editorLangId == latex && editorTextFocus",
Keep in mind that you probably need to do some tweaking here.
Almost. :wink:
{r, engine='bash', code_block_name} ...
"when": "editorlangId == latex && editorTextFocus",
Anyway, thank you.
oh, for me the L has to be capitalized or it wont work.
If you want to make it active for a precise file extention such as ".tex" you can use resourceExtname == .tex
I also replaced editorTextFocus by editorHasSelection which is better suited to my needs.
I finally end up with the following:
"when": "editorHasSelection && resourceExtname == .tex",
Most helpful comment
You can use Visual Studio Codes internal
keybindings.jsonfor this, here is an example:Explanation
keyclause declares which key should be pressed to trigger from the accepted keys.commandclause let's vscode know that this is a snippet insert command read more here.whenclause let's vscode know what context it is used in, as described hereNote:_You can "chain" multiple clauses using
&&in for instance thewhenclause, see example above._args.snippet${TM_SELECTED_TEXT}wraps around as you asked. you can see possible variables here.$0sets position of cursor after command has triggered.