Home > Back-end >  How can I use shortcut add markdown codeblock to selection text in vscode?
How can I use shortcut add markdown codeblock to selection text in vscode?

Time:10-21

I am working on some documents in words and evernote, need convert the contents to markdown and save to obsidian.

What I usually do is manually add code block :

```python
import xxx
some_content = 'balabala'

more = ....

```

As you know ctrl # is add comment to every line.

So I wonder if there is any way to

  1. use cursor make selection of text

  2. hit a shortcut to wrap that text with

    ```language
    selected text
    ```
    

I have search in google but nothing useful found.

CodePudding user response:

Does this key binding help

  {
    "key": "ctrl i 1",  // or any other combo
    "command": "editor.action.insertSnippet",
    "when": "editorTextFocus",
    "args": {
      "snippet": "```python\n$TM_SELECTED_TEXT\n```\n$0"
    }
  }

You can add a language selection:

  {
    "key": "ctrl i 1",
    "command": "editor.action.insertSnippet",
    "when": "editorTextFocus",
    "args": {
      "snippet": "```${1|python,javascript|}\n$TM_SELECTED_TEXT\n```\n$0"
    }
  }
  • Related