gpt4 book ai didi

json - Visual Studio 代码片段作为键盘快捷键

转载 作者:行者123 更新时间:2023-11-27 22:49:27 28 4
gpt4 key购买 nike

我知道如何修改和创建代码片段,也知道如何修改快捷键,但如何将这两者结合起来呢?

最佳答案

请注意,下面的行将打开为您当前使用的语言定义的片段列表(您不希望这样)

"args": { "snippet": "'$TM_SELECTED_TEXT'" }

而在下面的行中,作为参数给出的代码段将立即执行

"args": { "name": "your_snippets_name" }

下面是我如何为 HTML 定义一个片段,我想在其中选择一个文本,当按下 CTRL+B 时,文本将包含在 <strong></strong> 中。标签:

"make_strong": {
"prefix": "strong",
"body": [
"<strong>$TM_SELECTED_TEXT${1:}</strong>"
],
"description": "Encloses selected text in <strong></strong> tags"
}

Note the ${1:} above - what this does is that it places the cursor there. This enables you to press CTRL+B at cursor and then have the cursor placed inside the <strong></strong> tags. When selecting a string and pressing CTRL+B, the string will enclosed in <strong> tags and the cursor will be placed before the closing </strong> tag. Pressing TAB at this point, will put your cursor after the closing </strong> tag.

并添加到我的keybindings.json以下内容:

{
"key": "ctrl+b",
"command": "editor.action.insertSnippet",
"args": { "name": "make_strong" }
}

2021 年 6 月 2 日更新

因为这有很多观点,所以我发布了一些我使用的片段,也许对某些人有用

{
"key": "ctrl+alt+u",
"command": "editor.action.transformToUppercase"
},
{
"key": "ctrl+alt+l",
"command": "editor.action.transformToLowercase"
},
{
"key": "ctrl+b",
"command": "editor.action.insertSnippet",
"args": { "name": "insert_strong" }
},
{
"key": "ctrl+i",
"command": "editor.action.insertSnippet",
"args": { "name": "insert_italic" }
},
{
"key": "ctrl+u",
"command": "editor.action.insertSnippet",
"args": { "name": "insert_underline" }
},
{
"key": "ctrl+alt+p",
"command": "editor.action.insertSnippet",
"args": { "name": "insert_paragraph" }
},
{
"key": "ctrl+shift+space",
"command": "editor.action.insertSnippet",
"args": { "name": "insert_nbsp" }
},
{
"key": "ctrl+enter",
"command": "editor.action.insertSnippet",
"args": { "name": "insert_br" }
},

关于json - Visual Studio 代码片段作为键盘快捷键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59519880/

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