跳转至

Snippet issue

📋 VSCode Markdown 片段配置完整总结

核心问题

在 VSCode 中输入 fig 快捷方式无法触发 Markdown 代码片段补全菜单。


解决过程(从错误到正确)

❌ 第一个错误

只配置了片段文件(markdown.json),没有修改 VSCode 设置。 - 原因:没有意识到 Markdown All in One 扩展会干扰补全菜单触发 - 教训:扩展配置常会覆盖原生行为,需要显式调整

✅ 正确的完整方案

步骤1:编辑片段文件Ctrl+Shift+P > Configure User Snippets > Markdown)

{
  "figure": {
    "prefix": "fig",
    "body": [
      "<figure>",
      "\t<img src=\"$1\" alt=\"$2\">",
      "\t<figcaption>$3</figcaption>",
      "</figure>"
    ],
    "description": "Figure element with image and caption"
  }
}

步骤2:调整 VSCode 设置.vscode/settings.json

"[markdown]": {
    "editor.defaultFormatter": "yzhang.markdown-all-in-one",
    "editor.quickSuggestions": {
        "other": true,
        "comments": false,
        "strings": false
    },
    "editor.suggest.showSnippets": true,
    "editor.suggest.snippetsPreventQuickSuggestions": false
}


关键设置解释(下次遇到类似问题时的思路)

设置项 作用 为什么需要
editor.quickSuggestions.other 启用快速建议 让补全菜单在输入时立即出现
editor.suggest.showSnippets 强制显示片段 确保片段在补全菜单中可见
editor.suggest.snippetsPreventQuickSuggestions 禁用片段阻止快速建议 防止扩展阻止补全触发

下次避免的错误

  1. 只改片段,不改设置 — 片段必须配合 editor 设置才能触发
  2. 忽视扩展干扰 — 使用了扩展后,要检查它是否改变了原生行为
  3. 没有逐步验证 — 配置后应立即在 Markdown 文件中输入 fig 测试

验证方法

  • .md 文件中输入 fig → 立即看到补全菜单 → 回车完成补全 ✓

现在配置已稳定运行! 🎉