visual-studio-code

How can I open a .md file in VS Code preview mode from terminal?


VS Code has a good preview mode for .md files. To open a file with this mode, I have to right-click the file in VS Code document tree, and click "Open Preview". One can also use shortcut Ctrl+Shift+V.

I would like to open a .md file in VS Code preview mode directly from Ubuntu's terminal.

I guess the command I'm looking for will be something like code README.md --preview ... but running code --help didn't help me to find my answer.

Is there any way I can do that?


Solution

  • Open VSCode settings.json file with;

    Add these lines to json file before the last }

        , // don't forget the comma
        "workbench.editorAssociations": {   
            "*.md": "vscode.markdown.preview.editor",
        }
    
    

    Vs code settings json

    Then whenever you want, you can use code README.md command.