在 vscode 中设置字符 $ 以将文本包装为括号 [英] Setting character $ to wrap text as parentheses in vscode

查看:32
本文介绍了在 vscode 中设置字符 $ 以将文本包装为括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设存在以下代码.

sample text

当用户双击text,然后按{(,它只是在保留文本的同时包装文本.

When user double click text, then press { or (, it just wraps the text while keeping it.

sample {text}
sample (text)

但我不知道如何将此规则应用于 VS Code 设置中的 $.我期待的是

But I don't know how to apply this rule to $ in VS Code Settings. What I expect is

sample $text$

VS Code 中的哪些设置与此功能相关?

Which setting in VS Code is related to this feature?

推荐答案

编辑>自动环绕

是 vscode 中的设置.但它只适用于引号和括号,如 ()、{}、<>和 [] (可能还有一些其他语言定义的情况).不幸的是,您无法更改该设置以包含另一个字符,例如 $.

is the setting in vscode. But it only applies to quotes and brackets like (), {}, <> and [] (and possibly some other language-defined cases). You cannot change that setting to include another character like $ unfortunately.

这是您可以尝试的键绑定(在 keybindings.json 中):

Here is a keybinding you might try (in keybindings.json):

{
  "key": "alt+4",         // or whatever keybinding you wish
  "command":  "editor.action.insertSnippet",
  "args": {
    //  "snippet": "\\$$TM_SELECTED_TEXT\\$"

       // to have the text still selected after the $'s are inserted, use this
    "snippet": "\\$${1:$TM_SELECTED_TEXT}\\$"
  },
  "when": "editorTextFocus && editorHasSelection"
},

这样,当您选择任何选定的文本时,它都会被 $alt+4(其中 $ 在英文键盘上).如果您经常进行该操作,那可能是值得的.

So that any selected text will be wrapped by a $ when you select it and alt+4 (where the $ is on an English keyboard). If you do that operation a lot it might be worth it.

如果您在上面的代码段中使用这一行:

If you use this line instead in the snippet above:

    "snippet": "$1$TM_SELECTED_TEXT$1"  // or

    "snippet": "$1${2:$TM_SELECTED_TEXT}$1"

然后更一般地选择要环绕的文本,触发该键绑定并键入要环绕选择的任何字符和数量.

then more generically select text to surround, trigger that keybinding and type whichever and how many characters you want to wrap the selection.

这篇关于在 vscode 中设置字符 $ 以将文本包装为括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆