Skip to content

Markdown preview is not automatically opened when md file is opened via command-line and no VS code instance was already running #197374

Description

@jpstotz

Does this issue occur when all extensions are disabled?: Yes

I read various topics on how to achieve that Markdown files are automatically displayed as preview (e.g. #2766, https://stackoverflow.com/a/63541437/150978).

The only partial working solution was adding in setting.json

    "workbench.editorAssociations": {
        "*.md": "vscode.markdown.preview.editor"
    }

However this only works if VS code is already running. If no VS code instance is running and you execute code C:\<somepath>\test.md then the md file is opened in edit view and not preview mode.

Version: 1.84.0 (user setup)
Commit: d037ac076cee195194f93ce6fe2bdfe2969cc82d
Date: 2023-11-01T11:29:04.398Z
Electron: 25.9.2
ElectronBuildId: 24603566
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Windows_NT x64 10.0.19045

Steps to Reproduce:

  1. Change the setting change shown above.
  2. Create a simple markup file C:\temp\test.md
  3. Close all open VS code instances
  4. Execute code C:\temp\test.md
  5. VS code opens and show the editor of the md file

If you repeat the steps but in step 3 do not close all VS code instances, but have one instance running in step 5 correctly the preview will be displayed.

Why does it make a difference if a VS code instance is already running or not? It should not make a diference, so the current behavior is not deterministic which in my opinion means it is a bug.

Activity

  1. added
    bug
    help wanted
    custom-editors
    on Dec 4, 2023
  2. added this to the Backlog milestone on Dec 4, 2023
  3. manav014 commented on Jul 20, 2024

    @manav014

    I tried reproducing this issue with the latest stable release using following configuration.

    Version: 1.91.1
    Commit: f1e16e1e6214d7c44d078b1f0607b2388f29d729
    Date: 2024-07-09T22:07:46.768Z
    Electron: 29.4.0
    ElectronBuildId: 9728852
    Chromium: 122.0.6261.156
    Node.js: 20.9.0
    V8: 12.2.281.27-electron.0
    OS: Darwin arm64 23.5.0
    

    And I couldn't reproduced the issue. Steps I followed to reproduce are as follows:

    1. Set the editorAssociations setting in user settings.
    2. Force quit all instances of VS Code running.
    3. Open a .md file using code command.
    4. The .md file was opened in preview mode itself.
      PFA - POC video
    Screen.Recording.2024-07-21.at.2.43.59.AM.mov
  4. jpstotz commented on Jul 21, 2024

    @jpstotz
    Author

    Just retried it on a different Windows 11 system and the behavior is mostly as described in my initial post: md file is opened only in editor view.

    The strange part is that it is non-deterministic. If the folder the md file is located in is not a trusted path I am getting in 90% of all cases the pure edit view. And in about 10% the full-screen MD preview as shown in Manav Agarwal (@manav014) video pops up.

    If I add the folder to the list of trusted folders then then it works similar just in 90% of all cases the vertical split view is shown with left the editor and right the preview. And in 10% of all cases only the full-screen preview is shown.

    Version: 1.91.1 (system setup)
    Commit: f1e16e1e6214d7c44d078b1f0607b2388f29d729
    Date: 2024-07-09T22:06:49.809Z
    Electron: 29.4.0
    ElectronBuildId: 9728852
    Chromium: 122.0.6261.156
    Node.js: 20.9.0
    V8: 12.2.281.27-electron.0
    OS: Windows_NT x64 10.0.22631
    
  5. tomwheeler commented on Apr 23, 2026

    @tomwheeler

    I believe this bug affects not only a file opened from the command line, but also a file opened through the openFiles feature in Codespaces. That is, when I have openFiles configured to open my README.md file, it is shown as raw Markdown code in the editor. If I click the file icon in the explorer view to open it, it's displayed in Preview mode as it should be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugcustom-editorshelp wanted

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions