Vscode-markdown: Is there a keyboard shortcut for code block?

Created on 24 Oct 2018  路  3Comments  路  Source: yzhang-gh/vscode-markdown

I am able to create keybinding for code span (markdown.extension.editing.toggleCodeSpan) which surrounds the text with backticks.

Is it possible to setup keybinding for code block (triple backticks or 4-space indent)?

input Question Answered

Most helpful comment

Go to File > Preferences > Keyboard Shourtcuts with ctrl + k ctrl + s. Type markdown code and set any hot keys. It's markdown code block hot key.
image
Result:
peek 2018-12-06 13-12

All 3 comments

You can add

{
    "key": "your keybinding",
    "command": "editor.action.insertSnippet",
    "args": {
        "snippet": "```\n$0\n```"
    },
    "when": "editorTextFocus && editorLangId == markdown"
}

to your keybindings.json which can be opened here

image

Thanks, looks powerful. I enhanced it a bit to include the selected text, when shortcut is pressed on a selection.

{
    "key": "ctrl+shift+C",
    "command": "editor.action.insertSnippet",
    "args": {
        "snippet": "```\n${TM_SELECTED_TEXT}$0\n```"
    },
    "when": "editorTextFocus && editorLangId == markdown"
}

Go to File > Preferences > Keyboard Shourtcuts with ctrl + k ctrl + s. Type markdown code and set any hot keys. It's markdown code block hot key.
image
Result:
peek 2018-12-06 13-12

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chuyangliu picture chuyangliu  路  5Comments

asbjornu picture asbjornu  路  5Comments

MonsieurMan picture MonsieurMan  路  3Comments

jerry-sky picture jerry-sky  路  4Comments

akshaybabloo picture akshaybabloo  路  3Comments