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

如何在VS Code中通过tasks.json在侧边栏显示Markdown预览(不打开文件)

Preview test.md in VS Code Without Opening It (Using tasks.json)

The Command You Need

VS Code's built-in command to trigger Markdown preview is markdown.showPreviewToSide (use markdown.showPreview instead if you want a full-tab preview). To target a specific file without opening it, you'll pass the file path as an argument via the VS Code CLI.

Step-by-Step Setup

1. Open tasks.json

Press Ctrl+Shift+B (macOS: Cmd+Shift+B), select "Create tasks.json file from template", then choose "Others" to get a blank template.

2. Add the Preview Task

Replace the default content with this configuration:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Preview test.md",
      "type": "shell",
      "command": "code",
      "args": [
        "--command",
        "markdown.showPreviewToSide",
        "${workspaceFolder}/test.md"
      ],
      "problemMatcher": []
    }
  ]
}

3. Run the Task

  • Press Ctrl+Shift+B again, select the "Preview test.md" task from the list.
  • The Markdown preview will open in the side panel, and test.md won't be loaded into an editor tab.

Key Details

  • Ensure the code command is in your system PATH: install it via VS Code's command palette (Ctrl+Shift+P) by searching for "Shell Command: Install 'code' command in PATH".
  • Adjust the file path in args if test.md is in a subdirectory (e.g., ${workspaceFolder}/docs/test.md).
  • Swap markdown.showPreviewToSide with markdown.showPreview to open the preview in a standalone tab instead of the side panel.

内容的提问来源于stack exchange,提问作者Abhishek Chavhan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 04:00:05