How to activate automatic angle bracket `<>` pairing completion in Visual Studio Code?

社会主义新天地 提交于 2021-02-11 12:26:49

问题


I just couldn't find out how to activate automatic angle bracket <> pairing in Visual Studio Code like it exists for parentheses {}, round () or box [] bracket. Anyone has any clue, where in the setting I could configure this?


回答1:


There is no setting in vscode that allows you to change what is considered to be a bracket, like adding <>.

There is an issue Autoclosing pairs should be configurable that discusses this and you may wish to upvote it. In that issue, it is mentioned that you could edit the language configuration file to add your own "brackets" to the list. On Windows the javascript language configuration file is located at:

C: \Users\Mark\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\javascript\javascript-language-configuration.json;

as are the other languages (you don't say which language(s) you are interested in). Javascript doesn't normally support bracket matching for <> but I added that functionality by editing the file like so:

{
    "comments": {
        "lineComment": "//",
        "blockComment": [ "/*", "*/" ]
    },
    "brackets": [
        ["<", ">"],                       // added
        ["{", "}"],
        ["{", "}"],
        ["[", "]"],
        ["(", ")"]
    ],
    "autoClosingPairs": [
        { "open": "<", "close": ">" },    // added
        { "open": "{", "close": "}" },
        { "open": "[", "close": "]" },
        { "open": "(", "close": ")" },
        { "open": "'", "close": "'", "notIn": ["string", "comment"] },
        { "open": "\"", "close": "\"", "notIn": ["string"] },
        { "open": "`", "close": "`", "notIn": ["string", "comment"] },
        { "open": "/**", "close": " */", "notIn": ["string"] }
    ],
    "surroundingPairs": [
        ["<", ">"],                       // added
        ["{", "}"],
        ["[", "]"],
        ["(", ")"],
        ["'", "'"],
        ["\"", "\""],
        ["`", "`"]
    ],
    "autoCloseBefore": ";:.,=}])>` \n\t",
    "folding": {
        "markers": {
            "start": "^\\s*//\\s*#?region\\b",
            "end": "^\\s*//\\s*#?endregion\\b"
        }
    }
}

and it works - after a reload, demo in javascript file:

Now, this file will be overwritten on updates so I would keep a copy around elsewhere with a pointer to its location.


The other option - not as nice, no surround feature for example, is to make a snippet with < as the prefix (in one of your snippets files).

"angle bracket": {
  "prefix": "<",
  "body": [
    "<>"
  ],
  "description": "complete angle bracket"
}, 

After you type < you will have to tab to complete it. this also works.




回答2:


if I understood correctly well it s in settings - text editor - automatic brace completion



来源:https://stackoverflow.com/questions/62068072/how-to-activate-automatic-angle-bracket-pairing-completion-in-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!