You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改VS Code代码片段,使其完成后选中或复制指定文本

修改VS Code代码片段实现自动选中/复制指定文本

我需要修改我的VS Code代码片段,让它执行完成后,能把输出里的某段文本自动选中或者复制到剪贴板。

当前使用的代码片段如下:

"new section heading with link": {
    "prefix": "iheading",
    "body": [
        "$1## ${CLIPBOARD}",
        "",
        "This section: [${2:${CLIPBOARD}}](${TM_FILENAME}#${CLIPBOARD/(([\\w-]*)([^\\w\\s]*)*(\\s)*)/${2:/downcase}${4:+-}/g}) | [Back to top](#top)"
    ],
    "description": "Insert heading and link to section whose heading text is in the clipboard"
}

这个片段用于Markdown文件,比如复制文本“Howdy”后,在名为“notes.md”的文档中运行片段,输出内容为:

## Howdy

This section: [Howdy](notes.md#howdy) | [Back to top](#top)

我希望片段执行结束后,[Howdy](notes.md#howdy)这段文本能被选中或者复制,方便后续操作。


更新记录

  • 2025年1月13日 上午9:12:07 - 修正错误发布的旧版宏,替换为实际版本。
  • 2025年1月14日 上午9:59:36 更新

以下是经@Mark建议修改后的最终代码片段:

"new section heading with link": {
    "prefix": "iheading",
    "body": [
        "## ${CLIPBOARD}",
        "",
        "This section: ${1:[${CLIPBOARD}](${TM_FILENAME}#${CLIPBOARD/(([\\w-]*)([^\\w\\s]*)*(\\s)*)/${2:/downcase}${4:+-}/g})} | [Back to top](#top)"
    ],
    "description": "Insert heading and link to section whose heading text is in the clipboard"
}

内容的提问来源于stack exchange,提问作者Robert Mark Bram

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 02:07:08