How do I duplicate a line or selection within Visual Studio Code?

前端 未结 17 2138
青春惊慌失措
青春惊慌失措 2020-12-04 04:38

Using Microsoft\'s Visual Studio Code, how do I duplicate a line of code and then move it up and down? (Similar to Sublime\'s cmd+shift+d be

相关标签:
17条回答
  • 2020-12-04 04:59

    If you coming from Sublime Text and do not want to relearn new key binding, you can use this extension for Visual Code Studio.

    Sublime Text Keymap for VS Code

    This extension ports the most popular Sublime Text keyboard shortcuts to Visual Studio Code. After installing the extension and restarting VS Code your favorite keyboard shortcuts from Sublime Text are now available.

    https://marketplace.visualstudio.com/items?itemName=ms-vscode.sublime-keybindings

    0 讨论(0)
  • 2020-12-04 05:01

    It miss an answer to this question, "How to duplicate selection of code" Similar to Sublime's cmd/ctrl+shift+d or Jetbrains' cmd/ctrl+d behaviour.

    Install plugin Duplicate selection or line from VS Code Marketplace

    This extension provides bindings for ctrl+d (Windows/Linux) and cmd+d (MacOS). To customize keyboard shortcuts Preferences -> Keyboard Shortcuts:

    {
      "mac": "cmd+d",
      "key": "ctrl+d",
      "command": "geeebe.duplicateText",
      "when": "editorTextFocus"
    }
    

    Note : The shortcut does also the duplicate line so if you install it, remove your previous ctrl+d shortcut on copyLinesDownAction (if you did it before) otherwise duplicate selection can bug.

    0 讨论(0)
  • 2020-12-04 05:01

    Problem

    There seems to be a problem with the original "duplicate line down" shortcut on Ubuntu, mostly due to a conflict with an already existing workspace related shortcut on the operating system.

    Workaround

    However, an easy workaround is to simply ctrl+c (copies the entire line) and ctrl+v (pastes the copied line on to a new one)... Effectively, given you the same end result.

    0 讨论(0)
  • 2020-12-04 05:02

    For Linux users: I noticed what on Linux you quite an often need to use win key. For Windows combo is:
    ctrl + shift + alt + up

    then for Linux is same just add win key:
    ctrl + shift + win + alt + up

    I noticed that in a few combos now. Say ctrl + alt + L locks Linux, but ctrl + win + alt + L for Intellij formats code. Under Windows is just ctrl + alt + L to format the code.

    0 讨论(0)
  • 2020-12-04 05:03
    • For Jetbrains IDE Users who migrated to VSCode , no problem.

    • Install:
      1) JetBrains IDE Keymap: Extension
      2) vscode-intellij-idea-keybindings Extension (Preferred)

    • Use this Intellij Darcula Theme: Extension

    • The keymap has covered most of keyboard shortcuts of VS Code, and makes VS Code more 'JetBrains IDE like'.

    • Above extensions imports keybindings from JetBrains to VS Code. After installing the extension and restarting VS Code you can use VS Code just like IntelliJ IDEA, Webstorm, PyCharm, etc.

    0 讨论(0)
  • 2020-12-04 05:04

    in my last version Visual Studio Code 1.30.2 it wil be change automatically into


    ctrl + D

    0 讨论(0)
提交回复
热议问题