[英]User-defined keyboard shortcut on highlighted text in vscode
I need to create a shortcut that does the following:我需要创建一个执行以下操作的快捷方式:
I want to highlight text (say TEXT is highlighted) in the editor in vscode, and on triggering a keyboard shortcut, I need to replace it with say [\something TEXT].我想在 vscode 的编辑器中突出显示文本(比如突出显示文本),并且在触发键盘快捷键时,我需要用说 [\something TEXT] 替换它。 How can I do this?我怎样才能做到这一点?
I tried adding the following to keybindings.json, of course, this does not work:我尝试将以下内容添加到 keybindings.json,当然,这不起作用:
{
"key": "ctrl+r",
"command": "type",
"args":{
"text":"{\\color{red}%TEXT%}"
},
"when": "editorTextFocus"
}
You can use extension Regex Text Generator您可以使用扩展正则表达式文本生成器
{
"key": "ctrl+r",
"when": "editorTextFocus",
"command": "regexTextGen.generateText",
"args": {
"generatorRegex" : "\\{\\color\\{red\\}{{0}}\\}",
}
}
Just make it a keybinding that inserts a snippet.只需将其设置为插入片段的键绑定即可。 Then you can use variables like $TM_SELECTED_TEXT
.然后你可以使用像$TM_SELECTED_TEXT
这样的变量。
{
"key": "ctrl+r",
"command": "editor.action.insertSnippet",
"args": {
"snippet": "{\\color{red}${TM_SELECTED_TEXT}}"
},
"when": "editorTextFocus"
}
Select your text ( Ctrl + D or double-click it) and then trigger the keybinding above. Select 您的文本( Ctrl + D或双击它)然后触发上面的键绑定。
You could use the command type
but you need to use it twice in a macro: once before the keyword and once after, so it is easier to just use the insertSnippet
version.您可以使用命令type
,但需要在宏中使用两次:一次在关键字之前,一次在关键字之后,因此使用insertSnippet
版本更容易。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.