简体   繁体   English

VSCode 中用于 Markdown 链接的键盘快捷键?

[英]Keyboard shortcut in VSCode for Markdown links?

from other text editors I'm used to adding Markdown links by来自其他文本编辑器,我习惯于通过以下方式添加 Markdown 链接

  1. selecting the word I want to be linked,选择我想要链接的单词,
  2. pressing cmd-K on my Mac's / iPad Pro's keyboard, which puts square brackets around the marked word, appends a pair of normal parenthesis () and places the cursor right in beetween those two parenthesis so that I can在 Mac / iPad Pro 的键盘上按 cmd-K,在标记的单词周围加上方括号,附加一对普通括号 () 并将光标放在这两个括号之间,以便我可以
  3. just paste the URL I have in my clipboard into the right place by pressing cmd-V.只需按 cmd-V 将剪贴板中的 URL 粘贴到正确的位置。

So, select -> cmd-K -> cmd-V is a nice and short sequence for adding links in a Markdown document and cmd-K has become some kind of pseudo standard for adding links in several writing apps.因此,选择 -> cmd-K -> cmd-V 是在 Markdown 文档中添加链接的一个很好且简短的序列,而 cmd-K 已成为在多个写作应用程序中添加链接的某种伪标准。

However, in VSCode that's not possible.但是,在 VSCode 中这是不可能的。 But I'd love to make it possible.但我很想让它成为可能。 Any ideas?有任何想法吗? cmd-K is (hard-wired?) bound to listen for a next key press. cmd-K 是(硬连线的?)必须监听下一次按键。 But it doesn't have to be cmd-K.但它不必是 cmd-K。 I can learn another keystroke.我可以学习另一个击键。 But I need to be able to put additional text (square brackets and parenthesis) into the text and move the cursor to the right position.但是我需要能够将附加文本(方括号和圆括号)放入文本并将光标移动到正确的位置。 How's that done?那是怎么做的?

Thanks so much!非常感谢!

This extension Markdown All In One looks like it does what you want in one step.这个扩展Markdown All In One看起来像是一步完成你想要的。

Paste link on selected text在所选文本上粘贴链接

粘贴链接演示

Just select your link and hit Ctrl + V and it creates the link and inserts the clipboard link.只需选择您的链接并按Ctrl + V 即可创建链接并插入剪贴板链接。

If for some reason you don't want to use this extension, it would be pretty easy to create a snippet to do what you want.如果由于某种原因你不想使用这个扩展,创建一个片段来做你想做的事情会很容易。

Adding another answer that doesn't use the extension Markdown All In One I mentioned in the other answer and because a couple of commenters requested a different way.添加另一个不使用扩展Markdown All In One的答案,我在另一个答案中提到过,因为一些评论者要求采用不同的方式。 @MarcoLackovic @马可拉科维奇

  • First Method: keybinding in keybindings.json, then manually paste第一种方法:keybindings.json中的keybinding,然后手动粘贴
{
  "key": "alt+w",                  // use whatever keybinding you wish
  "command": "editor.action.insertSnippet",
  "args": {
    "snippet": "[${TM_SELECTED_TEXT}]($0)"
  },
  "when": "editorHasSelection && editorLangId == markdown "
}

Select the link text and, trigger your keybinding - the cursor will be placed where you want it and paste.选择链接文本并触发您的键绑定 - 光标将放置在您想要的位置并粘贴。


  • Second Method: use a macro to insert the snippet and paste in one step第二种方法:使用宏插入片段并一步粘贴

You will need a macro extension like multi-command to run multiple commands in series.您将需要像multi-command这样的宏扩展来连续运行多个命令。 Then this keybinding:然后这个键绑定:

{
  "key": "alt+w",
  "command": "extension.multiCommand.execute",
  "args": {
    "sequence": [
      {
        "command": "editor.action.insertSnippet",
        "args": {
          "snippet": "[${TM_SELECTED_TEXT}]($0)"
        }
      },
      "editor.action.clipboardPasteAction"
    ]
  },
  "when": "editorHasSelection && editorLangId == markdown "
}

Demo of second method:第二种方法演示:

Markdown 链接生成演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM