visual-studio-code - Setting character $ to wrap text as parentheses in vscode
问题描述
Suppose following code exists.
sample text
When user double click text
, then press {
or (
, it just wraps the text while keeping it.
sample {text}
sample (text)
But I don't know how to apply this rule to $
in VS Code Settings.
What I expect is
sample $text$
Which setting in VS Code is related to this feature?
解决方案
Edit> Auto Surround
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.
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"
},
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.
推荐阅读
- java - 使用一个类的多个限制器将数据存储在 firebase
- java - 如何从低安卓版本的安卓设备连接到Php服务器
- excel - 有没有办法从网络位置导入 Excel 模块 (VBA)?
- firebase - Firebase 规则:仅当用户包含在子节点中时才允许用户读取数据
- r - 如何在闪亮仪表板中更改侧边栏的字体大小
- python - 在 Selenium 中通过部分 Xpath 查找元素
- html - 在 Django 中获取请求
- asp.net-web-api - 具有复杂类型的 List 属性的 Url 语法
- css - SVG 掩码图像未在 Firefox 和 Edge 中显示
- python - 具有内部预测的自定义 Keras 损失函数