【问题标题】:In visual studio code how to keybind in the combination [alt + ctrl + '] the key [`]?在 Visual Studio 代码中,如何在组合 [alt + ctrl + '] 中键绑定键 [`]?
【发布时间】:2020-03-16 21:55:53
【问题描述】:

在 Visual Studio 代码中

如何在 alt + ctrl + ' 组合中进行键绑定以输出反引号 ` 作为引号?

我正在搜索要放入 keybindings.json

的特定命令
{
    "key": "alt+ctrl+\'",
    "command": "????????????command?????????????",
    "when": "editorTextFocus && !editorReadonly"
}

【问题讨论】:

    标签: visual-studio-code key-bindings vscode-snippets


    【解决方案1】:

    我假设您希望 Ctrl+Alt+' 输出反引号 `

     {
        "key": "ctrl+alt+'",
    
        // "command": "type",       // normally this would work
        // "args": {"text":"`"},
    
        // "command":  "editor.action.insertSnippet",  // this outs just one backtick
        // "args": {
        //   "snippet": "`"
        // },
    
      "command":  "editor.action.insertSnippet",
      "args": {
        "snippet": "`$TM_SELECTED_TEXT`"   // use this to wrap selected text with backticks
      },
    
        "when": "editorTextFocus && !editorReadonly"
     },
    

    通常,type 命令是您在此处使用的命令,但由于它输出反引号,vscode 会自动添加另一个 - 就像键入一个 " 输出两个。除非您设置您的 Editor > Auto Closing Quotes设置为never,但这会影响所有引号,而不仅仅是反引号。

    因此,如果您只想要一个反引号,请使用 insertSnippet 命令版本 - 它只输出一个反引号。

    【讨论】:

    • 当我使用这两种方法中的一种时,VSC 会插入反引号字符但不将其视为一种引号,因此如果我突出显示一个单词并进行组合,它会用字符替换该单词让我成为典型的附加和后挂。
    • 啊,那不一样 - 你想用反引号包围选定的文本吗?如果是这样,我修改了答案。
    猜你喜欢
    • 2021-12-01
    • 1970-01-01
    • 2021-09-04
    • 1970-01-01
    • 2010-09-24
    • 1970-01-01
    • 2020-09-14
    • 2012-01-17
    • 2010-11-23
    相关资源
    最近更新 更多