skip to Main Content

Using Ctrl+K V we can open markdown preview in side panel, but my requirement is different.

I want to add custom keyboard shortcut to open markdown preview for markdown file which is present my hard disc at any specific location.

Suppose I have D:testDatatest.md file. Now if I press any specific key (ex. ctrl+e) in vs code then preview of test.md should get displayed at right side panel in vs code.

2

Answers


  1. you can do that by editing Keyboard Shortcuts in vs code

    goto:
    Files > Preferences > Keyboard Shortcuts

    search for "ctrl+k v"

    you will see command: "Markdown: Open Preview to the Side"

    here you can edit the Keybinding to whatever you like.

    images for reference:

    keyboard shortcuts

    search for correct shortcut

    change the Keybinding

    Login or Signup to reply.
  2. You can set up a keybinding to do this with an extension I wrote, Find and Transform. For example, with this keybinding:

    {
      "key": "ctrl+e",          // whatever keybinding you want 
      "command": "findInCurrentFile",
      "args": {
        "run": [
          "$${",
            "const uri = vscode.Uri.file('C:\\Users\\Mark\\folder-operations\\CHANGELOG.md');",
            "vscode.commands.executeCommand('markdown.showPreviewToSide', uri);",
          "}$$",
        ],
        "runWhen": "onceOnNoMatches",
      }
    }
    

    Note that the backslashes need to appear as \\ – that represents each backslash being double-escaped.

    The only requirements are that an editor be focused and that your cursor is not at a "word" so there is no match (the extension is primarily designed to make find/searches easy and powerful so it would otherwise create the find). On an empty line or after punctuation for example.

    open markdown preview demo

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search