如何在Visual Studio Code中激活自动尖括号“<>"配对完成? [英] How to activate automatic angle bracket `<>` pairing completion in Visual Studio Code?

查看:207
本文介绍了如何在Visual Studio Code中激活自动尖括号“<>"配对完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是找不到如何在Visual Studio Code中激活自动尖括号<> 配对就像括号 {} ,圆()或方括号 [] 的括号一样.任何人都有任何线索,可以在设置中进行配置吗?

解决方案

vscode中没有设置可让您更改被认为是括号的内容,例如添加<> .

有一个问题

现在,此文件在更新时被覆盖,因此我将在其他位置保留一个副本,并带有指向其位置的指针.


另一种选择-不太好,例如没有环绕功能,是使用< 作为前缀(在您的一个摘录文件中)制作一个摘录.

 尖括号":{"prefix":<",身体": [<>"],"description":完整的尖括号"}, 

键入< 后,您将需要 tab 来完成它.这也有效.

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?

解决方案

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.

这篇关于如何在Visual Studio Code中激活自动尖括号“&lt;&gt;"配对完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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