vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Column selection

Open sirius1024 opened this issue 10 years ago • 59 comments

Just a remark, though: the default key bindings for "Shrink/expand selection" (Shift+Alt+Left/Right) conflict with a feature that doesn't exist yet, but which I hope will be implemented someday: column selection. In Visual Studio, and many other editors, if you hold Alt at the same time as you change the selection with Shift+arrows, it changes the selection across multiple lines. So Shift+Alt+arrows should be reserved for column selection, unless you plan to never implement this (very useful) feature.

sirius1024 avatar Dec 21 '15 01:12 sirius1024

@alexandrudima fyi

bpasero avatar Dec 23 '15 16:12 bpasero

So hope that Code can support such a useful feature.

zry656565 avatar Dec 29 '15 07:12 zry656565

I'd like to see this feature as well, much please and thanks!

groksrc avatar Jan 27 '16 18:01 groksrc

+1

diegostamigni avatar Feb 10 '16 12:02 diegostamigni

@SiriusGuo We support independent multiple cursors, which are slightly more powerful than column selection. So, you could use Ctrl+Alt+Down/Up to add more cursors and then regular shift+left/right to expand each cursor's selection. Or ctrl+shift+left/right, or end, etc.

@zry656565 @groksrc @diegostamigni Is there something I'm missing or can you get column selection and more with the multicursor support we already have?

multicursor

alexdima avatar Feb 22 '16 08:02 alexdima

The multicursor support is nice, but it's a workaround for editing columns of text. On mac Ctrl+Alt+Down/Up writes a non-printable character instead of adding cursors. I have Command+Alt+Down/Up mapped with Spectacle for window management so that doesn't work either. The best I can do is Command+Click for new cursors. I'd like to be able to just Alt+Click/Drag to select an area of text for editing like Sublime.

groksrc avatar Feb 22 '16 15:02 groksrc

@groksrc The default keybindings on mac are cmd+alt+down/up.

Perhaps Spectacle eats them up and they never reach us. Please try to edit your keybindings.json to change them. Specifically insert different keybindings in the key fields below:

[
{ "key": "ctrl+alt+up",           "command": "editor.action.insertCursorAbove",
                                     "when": "editorTextFocus" },
{ "key": "ctrl+alt+down",         "command": "editor.action.insertCursorBelow",
                                     "when": "editorTextFocus" }
]

alexdima avatar Feb 22 '16 16:02 alexdima

You are correct, Spectacle is eating them so they aren't reaching the editor. So these keybindings do work, but this still feels like a workaround. It's a lot of keystrokes to select something that's say 4 columns wide and 50 lines long.

Also, say you do something like add 4 cursors and select to the end of the line. Unless all of the lines are the same length your cursors are now in different columns. This is usually not what you want when doing columnar editing.

groksrc avatar Feb 22 '16 19:02 groksrc

Listen, vertical or column selection is a very simple concept, not including grander concepts like "multiple cursors". You put your cursor where you want to start, hold the Alt key down for the duration, and with the mouse move the cursor to the right and then down to create the desired box of selected text. One keystroke held down, the Alt Key, then a simple drawing action. Please, don't make this thing be some fangled 3-finger salute!

riclf avatar Feb 27 '16 02:02 riclf

// @alexandrudima

egamma avatar Feb 27 '16 17:02 egamma

@riclf Thank you for your input, I am really just trying to understand how the feature should work, I'm not trying to sell anything :).

I have pushed a change just now that adds column select with the mouse with the same modifiers as Visual Studio (Shift and Alt pressed), the key difference being currently our cursors cannot float on air (they get bounded by the text shape).

To better explain, here is VS: column-mouse-vs

Here is VSCode on master: column-mouse-vscode

Is this different behaviour a deal-breaker when it comes to using column selection? Again, I am asking to understand how the feature should work and how it is being used so I can figure out how to implement it.

alexdima avatar Feb 29 '16 16:02 alexdima

That works for me, what you have is the same as how it works in Sublime Text.

groksrc avatar Feb 29 '16 22:02 groksrc

Alexandru,

Thank you for reaching out. The way VS performs a vertical selection is the "correct" way, in that it is the classic way we expect that action to perform, coming from other editors.

Your second demo as VSCode performs on master is interesting and of value but not the expected behavior.

The problem with the current VSCode behavior is that it specifies in the design that the "box" selection will always be to an "end of line" condition, including the CR. An expected vertical selection would be my desired box of data, not always extended out to the CR at a variable horizontal distance. The current VSCode implementation is not a vertical selection box behavior. It is a variable length selection at each line.

In a perfect world the classic VS way would be the default, implemented with just an Alt Key and mouse draw. Then maybe your current VSCode way with a Alt+Shift and mouse movement, as a secondary option. But it is not very usable.

If I could only have one I would much prefer the expected classic behavior, as in VS, as that permits me to select the vertical data what I want/choose and not be forced to include more data + CR¹s in my selection.

Can we have the classic behavior as implemented in VS?

Thanks for asking !

-Ric

riclf avatar Feb 29 '16 22:02 riclf

@riclf, doesn't the 2nd example give the same 'result' as the 1st? It's just not as visually appealing.

Andrew-Gee avatar Mar 02 '16 12:03 Andrew-Gee

The second is how it works in sublime and atom, though I'd prefer just alt+drag like sublime.

Looking forward to this, working without it is painful...

crisward avatar Mar 02 '16 12:03 crisward

Interestingly, sublime doesn't put cursors on empty lines...

multi-cursor

crisward avatar Mar 02 '16 12:03 crisward

FYI, emacs CUA rectangle selection shows the rect on all lines (even empty lines.) Delete only affects populated lines (obviously) and never deletes a CR. Inserting does affect blank lines (e.g. see the comment chars.) And I personally like to nav with arrows, not the mouse.

test

I can't use an editor seriously without this feature. Thanks for working on it!

jcward avatar Mar 02 '16 13:03 jcward

@egamma, thank you for being so attentive to this issue. I saw your post on 1060 referring to this post as well :-) I wholeheartedly agree that the multiple cursors are more powerful...but sometimes "simpler" is what's needed. Is that not the heart and soul of Code in the first place? The current behavior, using "Insert Cursor Above/Below" yields ok-but-not-perfect results:

blockselectioncurrent

While I believe the desired behavior, some key combination (Alt seems traditional) and a mouse-drag is more flexible. EditPlus, like the several editors above, also displays this:

blockselectiondesired

I'd sure love to see this idea revisited as it's one of the hold-ups for my adoption of Code as well. Thank you again for all your hard work!

mphaney avatar Mar 02 '16 16:03 mphaney

+1 for using Alt+Drag to select a rectangular area.

Plus, using multiple cursors is powerful in some situations, but the behaviour is very dependent on Codes word boundaries, which are odd imho.

At the very least, the selection crosses lines as demonstrated above in e.g. the @egamma post and I don't see how that would ever be useful or intended.

And I'm using Visual Studio Code along full Visual Studio most of the time. The key combinations are absolutely alien to me. I'm wondering why Visual Studio Code doesn't align with full Visual Studio - possibly after (or before) selecting a(nother) (built-in) keyboard configuration.

ericwj avatar Mar 02 '16 17:03 ericwj

@alexandrudima The gif of your VSCode master example looks fantastic! Maybe perfect, depending on whether or not cursors should be placed on empty lines. I've never really thought about it before, to be honest, but I've never come across any issues when using editors that skip the empty lines when using column selection.

I would love to see Middle Click Drag without any key modifiers as one of the shortcuts (or the option to rebind to mouse buttons -- is this available?) for column selection so I can select columns without my keyboard. This matches one of the shortcuts sublime provides.

edit: Removed comments about multi cursor, they belong somewhere else.

dvlsg avatar Mar 03 '16 00:03 dvlsg