用于预定义文本替换的 VSCode shortcut/extension?

A VSCode shortcut/extension for predefined text substitution?

我正在为命名实体识别标记文本数据集。考虑以下示例:

{team:Alfreton Town} manager {manager:Nicky Law} says his players deserve huge credit for the character they have shown in their {league:Blue Square Bet Premier} relegation fight.

我必须找到各种类型的所有实体并将它们添加到类别前缀和后缀中。 我想做的是预定义几个快捷方式,例如:

我对 VScode 扩展不是很熟悉。是否有一些插件可以定义此类替换?

您不需要为此扩展。您可以定义一个片段,用其他内容(包括 selected 文本)替换一些 selected 文本。有关详细信息,请参阅 here

例如,使用这个片段

"Replace selection eith {team:Selection}": {
        "body": "{team:$TM_SELECTED_TEXT}",
        "prefix": "Selection",
        "description": "Insert hehehe"
    }

您可以 select

中的粗体文本

Alfreton Town manager Nicky Law says his players deserve huge credit for the character they have shown in their Blue Square Bet Premier relegation fight.

然后ctrl+shift+p,写"Insert Snippet"然后选择你新定义的片段。然后你得到

{team:Alfreton Town} manager Nicky Law says his players deserve huge credit for the character they have shown in their Blue Square Bet Premier relegation fight.

您还可以为片段定义 keybindings,实际上您将片段主体直接放在键绑定定义中(在这种情况下无需更改片段文件)。为此,打开您的键盘快捷键 json 文件并将以下代码放在那里

{
    "key": "ctrl+meta+t",
    "command": "editor.action.insertSnippet",
    "when": "editorTextFocus",
    "args": {
        "snippet": "{team:$TM_SELECTED_TEXT}"
    }
}

现在您可以 select 一些文本并使用 ctrl+meta+t 并且 selected 文本将被 {team:selected text} 替换。对于其他情况,您可以轻松地执行相同的操作,例如 ctrl+meta+m for manager 或者您可能更喜欢的任何其他键绑定。