programing tip

Visual Studio Code 내에서 줄 또는 선택을 복제하려면 어떻게합니까?

itbloger 2020. 10. 3. 10:06
반응형

Visual Studio Code 내에서 줄 또는 선택을 복제하려면 어떻게합니까?


Microsoft의 Visual Studio Code를 사용하여 코드 줄을 복제 한 다음 위아래로 이동하려면 어떻게해야합니까? (Sublime의 cmd+ shift+ d동작과 유사 )

지속적으로 사용하는 기능이며 Visual Studio Code를 사용하지 않고 어려움을 겪고 있습니다.


찾고있는 명령은 editor.action.copyLinesDownActioneditor.action.copyLinesUpAction입니다.

파일> 환경 설정> 키보드 단축키를 선택하여 연관된 키 바인딩을 볼 수 있습니다.

Windows :

Shift+ Alt+ DownShift+ Alt+Up

맥:

Shift+ Option+ DownShift+OptionUp

Linux :

Ctrl+ Shift+ Alt+ DownCtrl+ Shift+ Alt+Up

(숫자 패드 DownUpLinux 를 사용해야 할 수 있음 )

또한, 명령 editor.action.moveLinesUpAction과는 editor.action.moveLinesDownAction선을 이동하는 사람 그리고 그들은에 바인딩 Alt+ DownAlt+ UpWindows 및 Mac과에 Ctrl+ DownCtrl+ Up리눅스에서.


다음에서 키보드 단축키를 찾을 수 있습니다.

파일> 환경 설정> 키보드 단축키

기본 키보드 단축키는 다음과 같습니다.

행 아래로 복사 : shift+ alt+down

라인업 복사 : shift+ alt+up

줄 위로 이동 : alt+up

줄을 아래로 이동 : alt+down

또는 다음에서 키보드 단축키를 재정의 할 수 있습니다.

파일> 환경 설정> 키보드 단축키

그리고 편집 keybindings.json

예:

[
    {
        "key": "ctrl+d",
        "command": "editor.action.copyLinesDownAction",
        "when": "editorTextFocus"
    },
    {
        "key": "ctrl+shift+up",
        "command": "editor.action.moveLinesUpAction",
        "when": "editorTextFocus"
    },
    {
        "key": "ctrl+shift+down",
        "command": "editor.action.moveLinesDownAction",
        "when": "editorTextFocus"
    }
]

Sublime의 / + + 또는 Jetbrains의 / + 동작과 유사한 "코드 선택을 복제하는 방법"이라는 질문에 대한 답을 놓쳤습니다 .cmdctrlshiftdcmdctrld

VS Code Marketplace에서 플러그인 중복 선택 또는 줄 설치

Duplicate selection or line VS Code plugin

이 확장은 ctrl+ d(Windows / Linux) 및 cmd+ d(MacOS)에 대한 바인딩을 제공합니다 . 키보드 단축키 환경 설정-> 키보드 단축키 를 사용자 정의하려면 :

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

참고 : 바로 가기는 중복 라인도 수행하므로 설치하는 경우 이전 ctrl+ d바로 가기를 제거하십시오 (이전 에 수행 한 copyLinesDownAction경우). 그렇지 않으면 중복 선택이 버그를 일으킬 수 있습니다.


VScode에서 그들은 이것을 호출 Copy Line Up하고Copy Line Down

메뉴에서 다음으로 이동하십시오.

File > Preferences > Keyboard Shortcuts

Check already assigned keyboard shortcut for this, or adjust yours.

Sometimes the default assigned shortcut may not work, mostly because of OS.

In my Ubuntu, I adjusted this to: Ctrl+Shift+D

enter image description here


Try ALT+SHIFT+UP/DOWN

It worked for me!


In VSCode Ctrl+CCtrl+V duplicates the whole line below.

I prefer this to the accepted answer, because it only requires one hand to do this and feels way more natural.

The accepted answer will probably do it for most people, however Down sits the other side of the keyboard. So you have two options, use both hands on (Left Hand:L Shift+L Alt+ Right Hand:Up/Down), or with a single hand use the right R Shift+R Alt+Up/Down. The second option feels weird in my opinion. I'd rather use the option where my hand naturally sits on the keyboard, and if its one hand, even better.


Note that for Ubuntu users (<= 17.4), Unity uses CTRL + ALT + SHIFT + Arrow Key for moving programs across virtual workspaces, which conflicts with the VS Code shortcuts. You'll need to rebind editor.action.copyLinesDownAction and editor.action.copyLinesUpAction to avoid the conflict (or change your workspace keybindings).

For Ubuntu 17.10+ that uses GNOME, it seems that GNOME does not use this keybinding in the same way according to its documentation, though if someone using vanilla workspaces on 17.10 can confirm this, it might be helpful for future answer seekers.


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


Direct line duplication (without the clipboard step) is proposed by the Contextual Duplicate extension.

It is mapped on ctrl+K D


For Windows :

To Copy Up - shift+alt+up

To Copy Down - shift+alt+down

For mac :

To Copy Up - shift+option+up

To Copy Down - shift+option+down

For linux :

To Copy Up - ctrl+shift+alt+8

To Copy Down - ctrl+shift+alt+2

Note : You may change your keyboard shortcuts keybinding for visual studio code by pressing ctrl+shift+p, then type open keyboard shortcut in the pallet and then hit enter so new file will be opened (Key board shortcut file) you can see all the shortcuts over their and can change keybindings by clicking twice over the respective keybinding and then by entering your own keybinding, finally hit enter.

Hope this will help somebody!


For Fedora 29 workstation (Gnome 3.30.2) and Ubuntu users.

Unbind unnecessary left/right workspace keyboard combinations, list them by terminal

$ gsettings list-recursively | grep -E "org.gnome.desktop.wm.keybindings move-to-workspace-|org.gnome.desktop.wm.keybindings switch-to-workspace-"

Unbind them

$ gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-left "[]"
$ gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-right "[]"
$ gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-left "[]"
$ gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-right "[]"

Reset duplicate shortcuts

  • Super+Pgdown/PgUp , Ctrl+Alt+DownArrow/UpArrow
  • Super+Shift+PgDown/PgUp , Ctrl+Alt+Shift+DownArrow/UpArrow

They can be easily reset to work with only one shortcut in Settings>Devices>Keyboard
Only type again Super+PgUp for "Move to workspace above" as an example.

enter image description here

Now with less duplicate shortcuts in fedora29 all vscode shortcuts for linux must work fine


For people who have previously used any smart Jetbrains IDE composing of great shortcuts migrated to vscode , no problem.

Just install :
1) JetBrains IDE Keymap: Extension
2) vscode-intellij-idea-keybindings 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.


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


ctrl + D

참고URL : https://stackoverflow.com/questions/30203752/how-do-i-duplicate-a-line-or-selection-within-visual-studio-code

반응형