简体   繁体   English

VSCode 用键盘选择列

[英]VSCode column selection with keyboard

Any way to do this kind of selection using only the keyboard?有什么方法可以使用键盘进行这种选择?

在此处输入图像描述

With the regular Visual Studio I would use Shift + Alt + Arrows to get these columns selected.使用常规的 Visual Studio,我会使用Shift + Alt + Arrows来选择这些列。 Unfortunately it doesn't work in VSCode.不幸的是,它在 VSCode 中不起作用。

By default, this is Ctrl + Shift + Alt + Arrow .默认情况下,这是Ctrl + Shift + Alt + Arrow

If you would like to rebind it to align with Visual Studio, put this in your keybindings.json :如果您想重新绑定它以与 Visual Studio 保持一致,请将其放入keybindings.json

{
    "key": "shift+alt+down",
    "command": "cursorColumnSelectDown",
    "when": "editorTextFocus"
},
{
    "key": "shift+alt+left",
    "command": "cursorColumnSelectLeft",
    "when": "editorTextFocus"
},
{
    "key": "shift+alt+pagedown",
    "command": "cursorColumnSelectPageDown",
    "when": "editorTextFocus"
},
{
    "key": "shift+alt+pageup",
    "command": "cursorColumnSelectPageUp",
    "when": "editorTextFocus"
},
{
    "key": "shift+alt+right",
    "command": "cursorColumnSelectRight",
    "when": "editorTextFocus"
},
{
    "key": "shift+alt+up",
    "command": "cursorColumnSelectUp",
    "when": "editorTextFocus"
}

This will conflict with the default functions of that duplicating a line or growing/shrinking with smart select, so you can add this to swap those to require Control :这将与复制线或使用智能选择增长/收缩的默认功能冲突,因此您可以添加它以交换那些需要Control

,
{
    "key": "ctrl+shift+alt+down",
    "command": "editor.action.copyLinesDownAction",
    "when": "editorTextFocus && !editorReadonly"
},
{
    "key": "ctrl+shift+alt+up",
    "command": "editor.action.copyLinesUpAction",
    "when": "editorTextFocus && !editorReadonly"
},
{
    "key": "ctrl+shift+alt+right",
    "command": "editor.action.smartSelect.grow",
    "when": "editorTextFocus"
},
{
    "key": "ctrl+shift+alt+left",
    "command": "editor.action.smartSelect.shrink",
    "when": "editorTextFocus"
}

Here's what just worked for me with vscode:以下是使用 vscode 对我有用的内容:

Version: 1.39.2 (user setup)
Commit: 6ab598523be7a800d7f3eb4d92d7ab9a66069390
Date: 2019-10-15T15:35:18.241Z
Electron: 4.2.10
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Windows_NT x64 10.0.18362
  1. place cursor at upper left of block to select将光标放在块的左上角进行选择
  2. hold down ctrl-alt-shift按住 ctrl-alt-shift
  3. press down-arrow however many times you want多次按下向下箭头
  4. press right-arrow however many times you want多次按右箭头

When step 3 was to press right-arrow it didn't work for me.当第 3 步是按向右箭头时,它对我不起作用。

You can do column selection several ways,您可以通过多种方式进行列选择,

  • As you've noted, Place cursor to the start (left) of first word of first column press and hold Alt + Shift followed by Right Arrow to select top row (Try Ctrl + Shift if previous key combination is not working).正如您所指出的,将光标置于第一列的第一个单词的开头(左侧),按住Alt + Shift,然后按右箭头键选择顶行(如果前一个组合键不起作用,请尝试Ctrl + Shift )。 With the keys pressed proceed with selecting the column by pressing Down Arrow key.按下按键后,按向下箭头键继续选择列。

  • Place cursor to the start (left) of first word of first column Press and hold Alt + Shift and repeatedly press Down Arrow to add more cursors .将光标置于第一列第一个单词的开头(左侧)按住Alt + Shift并重复按向下箭头以添加更多光标 (Some versions of VSCode also use Ctrl+Shift instead) Once cursors added select the words by a simple Shift + Right Arrow (某些版本的 VSCode 也使用Ctrl+Shift代替)添加光标后,通过简单的Shift + 右箭头选择单词

  • Ctrl+D selects next occurrence of the word currently under cursor. Ctrl+D选择当前光标下出现的下一个词。

  • Ctrl+Shift+L selects all occurrences of word currently selected under cursor, regardless of if those words are above of below the cursor. Ctrl+Shift+L选择光标下当前选择的所有出现的词,无论这些词是在光标上方还是下方。

You can see your current keyboard shortcuts using the menu "File" -> "Preferences" -> "Keyboard Shortcuts".您可以使用菜单“文件”->“首选项”->“键盘快捷键”查看当前的键盘快捷键。 And then search by "cursorColum"然后通过“cursorColum”搜索在此处输入图片说明

It needs to install Visual Studio Keymap :它需要安装Visual Studio Keymap

  1. Open View -> Extensions (or Ctrl + Shift + X )打开视图 -> 扩展(或Ctrl + Shift + X
  2. Search for visual studio keymap搜索Visual Studio 键盘映射
  3. Install it & restart VSCode安装并重启 VSCode

Now column selection available by Shift + Alt + Arrows .现在可以通过Shift + Alt + Arrows 进行列选择。

See Column selection like Visual Studio and https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_43.md#column-selection-mode请参阅Visual Studiohttps://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_43.md#column-selection-mode 等列选择

Column selection mode may be coming in v1.43 or soon, see demo in link above.列选择模式可能会在 v1.43 或即将推出,请参阅上面链接中的演示。 It will be an option in the Selection menu.它将是“ Selection菜单中的一个选项。

Works best with mouse but key shortcuts possible too:使用鼠标效果最佳,但也可以使用快捷键:

While this is checked, selecting with the mouse will create a column selection and Shift+arrow keys and Shift+Page Up/Down keys will also create column selection.选中此项时,使用鼠标选择将创建列选择,Shift+箭头键和 Shift+Page Up/Down 键也将创建列选择。

I had to do the following:我必须执行以下操作:

  1. Open Keybind settings: ctrl+k,ctrl+s .打开键绑定设置: ctrl+k,ctrl+s
  2. Remove keybindings for Notebook: Copy Cell <Up/Down> and Copy Line <Up/Down> .删除Notebook: Copy Cell <Up/Down>键绑定Notebook: Copy Cell <Up/Down>Copy Line <Up/Down>
  3. Search keybindings for cursorColumnSelect <Up/Down> .搜索cursorColumnSelect <Up/Down>键绑定。
  4. Reassign the bindings that say When: textInputFocus to Shift+Alt+<arrow keys> .将显示When: textInputFocus的绑定重新分配给Shift+Alt+<arrow keys>

Sublime text has this shortcut to select columns: Ctrl + Alt + Up or Ctrl + Alt + Down. Sublime text 有这个 select 列的快捷方式:Ctrl + Alt + Up 或 Ctrl + Alt + Down。

So with adding this extension to VSCode: Sublime Text Keymap and Settings Importer.因此,将此扩展添加到 VSCode:Sublime Text Keymap and Settings Importer。

You can just use the shortcut and done..您可以使用快捷方式并完成..

Default keybinding in VSC... VSC 中的默认键绑定...

CMD ALT SHIFT ARROW (Mac) CMD ALT SHIFT ARROW (Mac)

CTRL ALT SHIFT ARROW (PC?) CTRL ALT SHIFT箭头(PC?)

This answer is for those who appreciate default keyboard shortcuts.这个答案适用于那些喜欢默认键盘快捷键的人。 I prefer them because they work (out of the box) when I use other machines and when starting up on a new Mac.我更喜欢它们,因为当我使用其他机器和在新 Mac 上启动时,它们可以(开箱即用)工作。

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

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