How do I get a cursor on every line in vscode - visual-studio-code

I'm trying to use the multi cursor functionality of vscode on a large(ish) file.
the file is too large to select every line individually with ctrl-alt-up or down. In sublime-text I would select everything and push ctrl-shift-l. Is there a similar thing in vscode. I've tried using a regex search for ^, but that gives me an error stating "Expression matches everything".

The command Selection / Add Cursors to Line Ends altshifti will put a cursor on every line in the current selection. (For mac use optshifti)
Tip: You can pull up the keyboard shortcut reference sheet with ctrlk,ctrls (as in, those two keyboard combos in sequence).
(For mac use cmdk,cmds)

Hold Alt+Shift and select the block. Then press End or Right button.
You get selected individual lines.
I use version VSCode 1.5.3 in Windows.

Hold Alt+Shift+i
Hold Home (fn+-> Mac) for right-most or End for left most(fn+<- Mac)

This feature is actually called split selection into lines in many editors.
Sublime Text uses the default keybinding, CTRLSHIFT L
VSCode uses ALTSHIFTI
For Atom you actually need to edit your keymap to something like this
'.platform-win32 .editor, .platform-linux .editor':
'ctrl-shift-L': 'editor:split-selections-into-lines'

Real Lines vs Display Lines
First we have to understand the difference between Real Lines and Display Lines to completely understand the answer of the question.
When Word Wrap is enabled, each line of text that exceeds the width of the window will display as wrapped. As a result, a single line in the file may be represented by multiple lines on the display.
The easiest way to tell the difference between Real Lines and Display Lines is by looking at the line number in the left margin of the text editor. Lines that begin with a number correspond to the real lines, which may span one or more display lines. Each time a line is wrapped to fit inside the window, it begins without a line number.
Cursor At the Beginning of each Display Lines:
Cursor At the Beginning of each Real Lines:
Answer to the Question
Now that we know the difference between Display Lines and Real Lines, we can now properly answer the actual question.
Hold AltShift and select the text block.
Press Home to put cursor on the beginning of every Display Line.
Press End to put cursor on the end of every Display Line.
Press HomeHome (Home twice) to put cursor on the beginning of every Real Line.
Press EndEnd (End twice) to put cursor on the end of every Real Line.
Please understand that AltShiftI put cursor on the end of every Real Line.

Install the extension Sublime Commands.
[Sublime Commands] Adds commands from Sublime Text to VS Code: Transpose, Expand Selection to Line, Split into Lines, Join Lines.
(Don't forget to add the keybinding(s) from the extensions details page to your keybindings.json)
Doesn't VS Code already have a "split into lines" command?
Yes, yes it does. However it differs from the one in Sublime.
In VS Code, when you split into lines your selection gets deselected and a cursor appears at the end of each line that was selected (except for the last line where the cursor appears at the end of the selection).
In Sublime, when you split into lines a cursor appears at the end of each line (with the same exception as in VS Code) and the selection is divided on each line and "given" to the same line.

I have the same problem, i'm used to Alt + drag to do 'box selections' in visual studio but it does'n work in code.
It seems to be impossible for now to do it differently than by selecting every single line.
However plugins should be supported soon so we will likely see a plugin for this if not implemented directly by microsoft.
From visual studio uservoice forums:
We plan to offer plugin support for Visual Studio Code. Thank you for your interests and look for more details in our blog in the coming weeks. http://blogs.msdn.com/b/vscode.
For the preview we are looking for exactly this type of feedback. Keep it coming.
Sean McBreen – VS Code Team Member

Related

Visual Studio Code select same position above and below not the whole line before and after (see image)

I'm using visual studio code and run into a weird problem. I'm not sure how I got here - I could have accidently pressed a shortcut unknowingly.
I'm trying to select a phrase, link or anything that crosses multiple lines (whether the lines are true lines or due to word wrap). When I select multiple lines, it doesn't automatically select the text at the start and end between the two points. Rather, it just selects the length of text for that line and repeats it in the subsequent lines. See the image below to understand.
Image of issue
As you can see, I am trying to select the words from "the" to the end of "sub". Instead of selecting all the words between the two, it selects the text "the instru" and selects every line with the same amount of characters/length.
In order to show what I am expecting, I have pasted the text into Notepad and done the same thing.
What I am expecting
As you can see, all the words between "the" and "sub" are selected.
If anyone has any idea about how to fix this, I would be greatly appreciative.
Below is a copy of the text if the images don't display.
Follow the instructions below for a click guide to retire and/or add 'School'.
Best practice if there is a change in 'School' structure would be to 'retire' any existing school setup that is no longer required and add the new sub school information. The reason why we don't just edit existing school names (typically) is due to leaving historical data intact.
Try using ctrl+shift+P and typing "Toggle Column Selection Mode"

VS Code multi-line select past ends of lines

I've been transitioning to using VS Code for my python projects after previously working with the full Visual Studio, and some of the key bindings/features I'm used to in Visual Studio I can't find the equivalent for in VS Code. I'm not sure if the bindings are different or if the feature doesn't exist.
One feature in particular that I can't figure out is if it is possible to do multi-line select past line endings. In Visual Studio, using Alt + Click + Drag, lets you create a multi-line cursor or box selection, that can extend past line ends, implicitly adding spaces as needed so that the right-most side of the box stays uniform. In VS Code, if you drag the selection past the end of a line, the selection box won't go past the end of the line, even if other lines in the selection extend past it. In Visual Studio, this feature even goes further, as you could Alt + Click + Drag even in areas with no characters as all, creating a multiline cursor or box selection to the right of all existing line ends.
This isn't an essential feature, but it's very handy in making code easy to read. For example, when assigning several dictionary entries all at once, with varying key lengths. Is it possible to do something like this in VS Code?
Edit: The feature I'm looking for is virtual spaces (thank you Mark for providing the feature name), which seems to be an outstanding feature request in VS Code.
The short answer is no, vscode does not have a box select, past line ends, built-in. VS Code does not have the concept of virtual spaces which would be necessary to make this work yet.
Below is the issue, lots of comments, not that many upvotes. Upvote it.
https://github.com/microsoft/vscode/issues/5402

How to put the cursor at the end of all selected lines in Visual Studio Code?

I have the following code:
CList.Add( new CodeStuff(941,"National List Limit
CList.Add( new CodeStuff(945,"Code not used
CList.Add( new CodeStuff(946,"State Building Height Limit
CList.Add( new CodeStuff(993,"Building Material Type
CList.Add( new CodeStuff(1033,"Not used - requirements changed
CList.Add( new CodeStuff(1034,"Current Unacceptable Applications
CList.Add( new CodeStuff(1035,"Historical Unacceptable Applications
I got the first bit using Alt+Shift+mouse button and typing. How do I add "); to the end of each line?
I had to use Notepad++ macro recording to do it and this is the only reason I still hang on to that editor. If someone can tell me how to do it in VSCode, I'd be very grateful.
Not completely sure I understand, but Shift-Alt-I will put a cursor at the end of all selected lines so just select your text and Shift-Alt-I (that is an 'eye' at the end). Then typing "); will put that at the end of each line.
---------------------- Edit -------------------------------
I see that Column Selection Mode (in v1.43) does this nicely now (with Selection/Column Selection Mode enabled) depending on your direction of selection [unfortunately the gif does a poor job of showing the cursors but they are all at the beginning or ends of the lines depending on the direction of selection]:
On Mac Vscode, I believe the trick is to "mouse" select the lines you wish to append, then hit Shift+Option+I.
On Windows 10, if I hit ShiftAltI, all the cursors go to the beginning of each line. To move the cursors to the end of each line, simply hit the End key after that.

Select multiple lines with cursors at each line start

I want to select multiple lines and put a cursor at the beginning of each line. Sublime Text can do this with Ctrl-Shift-L
select multiple lines
ctrl + shift + L and then put cursor at beginning of each line
Press Crtl + Shift + Alt + Arrow up/down to select multiple lines in Visual Studio Code. Note that the selected lines will be in one column (if possible).
You can also mark some lines and then do this combination and you have all selected lines included.
Moreover you can press and hold Alt and click the lines you need. This way you can select multiple lines that are not neighbours or in the same column.
To do exactly what Ctrl-Shift-L does in Sublime Text, you must do:
On Windows:
Select the lines.
Alt-Shift-I (will add multiple cursors)
Shift-Home (will go at the beginning of each line and be selected)
On Mac :
Select the lines.
alt-shift-I (will add multiple cursors)
cmd-shift-←
(will go at the beginning of each line and be selected)
More information in this answer.
Put cursor at beginning of first line
Ctrl-Shift-Alt-Arrow down/up will put a cursor at the beginning of the following/preceding lines
Ctrl-I will select those lines with the cursor at the beginning of each line.
NOTE : On my vscode the cursors look like they might be shifted down one line but they actually are not - the are in the right place. If you start typing, it works but you have to hit Enter when you are done to get back separate lines. It is a little quirky but works as you would expect.
EDIT (using a hint from #Maxime's answer)
Select your test first.
Alt-Shift-I : puts cursors at the end of each of those lines but text unselected (I as in island not a lowercase L)
Function-Home : put cursors at beginning of each line.
Ctrl-I : selects all lines.
Important: read the NOTE above.
--------------------- v1.43 see How to put the cursor at the end of all selected lines in Visual Studio Code? with column selection mode it is easy to put the cursor at the beginning or end of lines selected by dragging.
You can hold alt and click the places you need with the mouse. This way you can select rows that aren't related, like row 10,15,18. Also you can select at different places in the same row.
I hope this helps someone, but there is a setting in VSCode called Editor: Multi Cursor Modifier which may do what OP is asking:

How do you select a range of lines in Visual Studio Code?

How do you select a range of lines (from a start line number to an end line number) in Visual Studio Code?
I had to delete lines starting from line number 17158 through 1644546 which was nearly impossible to do if I used scrolling. So I followed 4 simple steps:
Go the line where you want to start deleting (17158 in my case).
Using keyboard, press Ctrl+G which opens a box to enter the line number to go to.
Enter the line number in the box (1644546 in my case). VS Code will take you to the line you wanted to go to.
Hold the shift key and click on the line. Hopefully, this should select all the lines that you wanted to delete.
Since version 1.46 it seems like you can set an anchor and select from anchor to cursor: https://code.visualstudio.com/updates/v1_46#_accessibility
First set a selection anchor (default binding Ctrl+K Ctrl+B)
Then go to the line that you want, either by mouse or by Go To Line command
Then Select From Anchor to Cursor (default binding Ctrl+K Ctrl+K)
To cancel selection hit esc.
Click at the first column of the first line. Then scroll down to the last line that you want to select, HOLD Shift key and click on the last line.
Try this out...
Type #region at the start of the line which you want to select and #endregion at the end of the line and collapse it using the side ruler available in VS code .Now since it will in a single region you can select the region easily
Hi y'all I found a really fun way to do it. Ctrl-= will select to the last go back.