【问题标题】:How to set the insertion of automatic space after a colon in Visual Studio Code?如何在 Visual Studio Code 中设置冒号后自动插入空格?
【发布时间】:2020-10-12 09:28:58
【问题描述】:

我想设置如果我写一个冒号,我会在它后面自动添加一个空格。我曾经使用 IntelliJ IDEA,它在使用 JSON 时会自动执行此操作。这也可以在 VSC 中设置吗?

【问题讨论】:

  • 如果您将键绑定添加到:type : (冒号空格)
  • 我编辑了文件 keybindings.json 像:{ "key": ":", "command": "type", "args": { "text": ": " } } 但是,不是工作。

标签: visual-studio-code vscode-settings


【解决方案1】:

扩展名HyperSnips 是一种方法。

在您的 json.hsnips 文件中(因此仅限于 json 文件):

snippet `:` "expand to : " A
``rv = ': '``
endsnippet

现在,无论何时您输入 :,它都会在 json 文件中扩展为 :

请参阅https://stackoverflow.com/a/62562886/836330 了解更多信息。


仅使用: 作为键绑定中前缀的键是行不通的,因为您必须有一个修饰键 - 例如 altctrl 等。见https://code.visualstudio.com/docs/getstarted/keybindings#_accepted-keys

你可以这样做:

{ 
  "key": "alt+;",      // I chose ; because it is on the same key for me as :
  "command": "type", 
  "args": { "text": ": " },
  "when": "editorTextFocus && editorLangId == json"
},

这样就行了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-18
    • 1970-01-01
    • 2017-09-21
    • 2022-07-17
    • 1970-01-01
    • 2016-07-06
    • 2020-10-13
    相关资源
    最近更新 更多