gpt4 book ai didi

How to disable automatic pairing of triple backticks in VS Code in Markdown files while keeping other auto-pairings?(如何在Markdown文件中禁用VS代码中的三重反勾自动配对,同时保留其他自动配对?)

转载 作者:bug小助手 更新时间:2023-10-26 20:15:55 30 4
gpt4 key购买 nike



I've been enjoying the features of Visual Studio Code, but there's one specific behavior that has been counterproductive for me: the automatic pairing of triple backticks (```) in Markdown files.

我一直很喜欢Visual Studio代码的功能,但有一个特定的行为对我来说适得其反:在Markdown文件中自动配对三个反引号(`)。


To clarify, I'm not looking to disable all auto-pairings—just the triple backticks. Whenever I type a single backtick, VS Code automatically completes it with two additional backticks. This is time-consuming to remove manually each time and disrupts my workflow.

要澄清的是,我并不打算禁用所有自动配对--只是禁用三个反号。每当我键入一个反标记时,VS代码都会自动用两个额外的反标记来完成它。每次手动删除都很耗时,而且会中断我的工作流程。


Here's an example of what happens:

以下是一个发生了什么的例子:


Markdown - VS Code - Triple Backticks

Markdown - VS Code -三重反勾


Is there a way to disable this feature? If not, could someone guide me on how to disable this behavior in my own settings?

有没有办法禁用这项功能?如果没有,有人可以指导我如何在我自己的设置中禁用此行为吗?


I've seen a similar question but it doesn't address my specific need to disable only the triple backticks while keeping other auto-pairings intact.

我看到过类似的问题,但它没有解决我的具体需要,只禁用三重反引号,同时保持其他自动配对完好无损。


I've also created an issue on GitHub to address this, but I'm wondering if there's a workaround or setting that I've missed.

我还在GitHub上创建了一个问题来解决这个问题,但我想知道是否有我错过的解决方法或设置。


Is there a way to achieve this? If not, could someone guide me on how to modify this behavior in my settings?

有没有办法实现这一点?如果没有,有人可以指导我如何在我的设置中修改此行为吗?




I tried searching through the VS Code settings and keybinding options to find a way to disable the automatic pairing of triple backticks specifically, but found no such setting. I expected to find an option that allows me to turn off this particular auto-pairing while keeping others. What actually happens is that every time I type a single backtick, it auto-completes to triple backticks, which I then have to manually remove.

我试图搜索VS代码设置和键绑定选项,以找到一种方法来专门禁用三个反引号的自动配对,但没有找到这样的设置。我希望找到一个选项,让我在保留其他自动配对的同时关闭这种特定的自动配对。实际发生的情况是,每次我输入一个反标记时,它都会自动完成为三个反标记,然后我必须手动删除它们。


I've also created a GitHub issue to address this concern. Additionally, I've commented on the commits in the VS Code repository where this feature was recently implemented, but have yet to find a solution or workaround.

我还创建了一个GitHub问题来解决这个问题。此外,我已经对VS代码存储库中的提交进行了评论,该功能最近在VS代码库中实现,但尚未找到解决方案或变通方法。


I was expecting to find an option within the VS Code settings that would allow me to disable the automatic pairing of triple backticks specifically, while keeping other auto-pairings active.

我希望在VS代码设置中找到一个选项,允许我专门禁用三个反标记的自动配对,同时保持其他自动配对处于活动状态。


更多回答
优秀答案推荐

VS Code has added the autoClosingPairs api mentioned below. I have updated and released (v0.6.0) of my extension, Custom Language Properties It is now easy to disable backtick closing completions in markdown files. Here is a demo from the extension README:

VS代码添加了下面提到的AutoClosingPair API。我已经更新并发布了我的扩展,自定义语言属性(v0.6.0)现在很容易在标记文件中禁用反引号结束完成。下面是扩展自述文件中的一个演示:


demo of extension modifying the markdown auto closing pairs completion in markdown files


Note that I removed completion for both single and triple backticks in the example.

请注意,我在示例中删除了单反号和三反号的补全。




You can also edit the language configuration file yourself. The only problem is that if it is ever updated by the vscode team you will have to re-do your changes.

您也可以自己编辑语言配置文件。唯一的问题是,如果vscode团队更新了它,你将不得不重新做你的更改。


On a Windows system, the relevant file is located at:

在Windows系统上,相关文件位于:


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

Here is what the autoClosingPairs key/value looks like for a markdown file:

以下是标记文件的AutoClosingPairs键/值的外观:


  "autoClosingPairs": [
{
"open": "{",
"close": "}"
},
{
"open": "[",
"close": "]"
},
{
"open": "(",
"close": ")"
},
{
"open": "<",
"close": ">",
"notIn": [
"string"
]
},
{
"open": "`", // consider deleting this as well
"close": "`"
},
{
"open": "```", // delete this {} entry and save
"close": "```"
}
],

You might want to make a back-up of that file first.

您可能需要先备份该文件。


I wrote an extension, Custom Language Properties, which has a command to show the language configuration file of the active editor:

我编写了一个扩展名为Custom Language Properties,它有一个命令来显示活动编辑器的语言配置文件:


Custom Language Properties: Show language configuration for current editor

It will open the relevant file (and the editor tab context menu Copy Path has its full path). In the editor which is opened you can edit and save the document. A reload is necessary for the edited language configuration file to take effect.

它将打开相关文件(并且编辑器选项卡上下文菜单复制路径具有其完整路径)。在打开的编辑器中,您可以编辑和保存文档。要使编辑后的语言配置文件生效,需要重新加载。


And you will no longer get autoclosing of triple backticks. But there is sone issue, if you type 3 backticks in a row now vscode considers the third bactick to be part of an autoclosingPair itself and adds a fourth backtick...arg @#$.

而且你将不再得到自动关闭的三个倒钩。但有一个问题,如果你连续输入3个反标记,现在vscode会将第三个反标记视为自动关闭Pair本身的一部分,并添加第四个反标记...arg@#$。


That can be solved by also deleting the

可以通过同时删除


    {
"open": "`", // consider deleting this as well
"close": "`"
},

making sure you don't leave any hanging commas in the json file.

确保没有在json文件中留下任何逗号。


BTW, I hate the triple backtick completion too.

顺便说一句,我也讨厌三重倒勾完成。


You should also upvote this issue: LanguageConfiguration interface should expose autoClosingPairs which would also allow my extension and others to fix the problem easily. In fact, this already works but since the api is still proposed so it cannot be published. But in testing it works as expected.

你也应该支持这个问题:LanguageConfiguration接口应该公开AutoClosingPair,这也可以让我的扩展和其他人很容易地修复这个问题。事实上,这已经起作用了,但由于API仍在建议中,因此无法发布。但在测试中,它的效果与预期不谋而合。


Demo is in a markdown file. Auto-closing works for {}()[]<> but not backticks because I excluded them in this extension's settings.

DEMO在一个降价文件中。自动关闭对{}()[]<>有效,但对反勾无效,因为我在此扩展的设置中排除了它们。


demo in markdown file with backticks not being auto-closed



I'm not 100% sure, but I think the answer might be that you can't. See the language configuration for the builtin Markdown extension, where ``` is only declared for auto-closing-pairs, but not as a bracket or quote type (makes sense, because it isn't), so you can't use the editor.language.brackets setting, and the editor.autoClosingBrackets has no effect on it. What you'll need if you want to do this through user configuration (instead of building your own modified VS Code or using a different Markdown extension than the builtin one) probably falls into the category of User settings for language configurations
#102574
, which I think would allow you to override autoClosingPairs.

我不能百分之百确定,但我认为答案可能是你不能。看看内置Markdown扩展的语言配置,其中``只为自动结束对声明,而不是作为方括号或引号类型(有道理,因为它不是),所以你不能使用editor.language.brorkets设置,而editor.autoClosingBrackets对它没有影响。如果您想通过用户配置(而不是构建自己修改的VS代码或使用与内置扩展不同的Markdown扩展)来完成此操作,则可能属于语言配置#102574的用户设置类别,我认为这将允许您覆盖AutoClosingPair。


Related Pull-Request which added backticks to auto-closing-pairs: Add ` as an autoClosingPair in markdown #184532 (release milestone: June 2023 (1.80)). Quoting from the description:

相关拉取请求,在自动关闭对中增加了反标记:在#184532(发布里程碑:2023年6月(1.8))中添加`作为自动关闭Pair。引用描述中的内容:



Fixes #183489


Will test this out to see if it's helpful or too annoying



更多回答

Dear @Mark, thank you for your thoughtful suggestion. It appears that your workaround aligns with my current approach, reaffirming that it may indeed be the sole viable option at this juncture. I shall mark your answer as correct to acknowledge its utility. Much appreciated.

亲爱的@Mark,谢谢你深思熟虑的建议。您的变通办法似乎与我目前的方法一致,重申这可能确实是此时此刻唯一可行的选择。我会把你的答案标记为正确,以承认它的作用。非常感谢。

Thanks for your reply. It's worth noting this wasn't an issue until a recent update. Given it was possible before, 'can't be done' is hard to accept. I hope this can be revisited in future updates or settings. Appreciate your input.

谢谢你的回复。值得注意的是,直到最近的一次更新之前,这并不是一个问题。考虑到它以前是可能的,“不能做”是很难接受的。我希望在未来的更新或设置中可以重新考虑这一点。感谢您的意见。

Thank you for your continued efforts to refine your answer. However, the information provided is already known to me and doesn't address my specific concern. For further context, you may refer to my comment on this topic: github.com/microsoft/vscode/commit/…. To clarify, I'm not looking to disable all auto-pairings—just the triple backticks.

感谢您为完善您的答案所做的持续努力。然而,我已经知道所提供的信息,并没有解决我特别关注的问题。关于更多的背景,你可以参考我对这个主题的评论:githeb.com/microsoft/vscode/Commit/…。要澄清的是,我并不打算禁用所有自动配对--只是禁用三个反号。

@Webia1 I'm not suggesting that you find a way to disable them all. Overriding autoClosingPairs would allow you to define it to contain everything that's there by default except for the backticks.

@Webia1我并不是建议你想办法把它们全部禁用。覆盖AutoClosingPair将允许您将其定义为包含缺省情况下除反号以外的所有内容。

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com