How to select whole line in VSCode - visual-studio-code

I am using VSCode on a Mac.
Does anyone know how to select the entire line that the cursor is on? I know about Command+I, but that only selects what appears to be the whole line, which is not always the whole line if I have word wrap enabled.
I am looking for something like Sublime Text's "Expand Selection to Line" command.

All you need to do is put the cursor anywhere on the line, do not make any selection at all and then do the desired command (Cut, copy, or paste).
When no text selected, VS Code will automatically select the entire line.

just triple click the end of the line it will select the entire line

Triple click at any point on the line
Click once on number of the line
Press Command + L

An alternative to what people have posted is, when your cursor is at the start/end of the line, you can hit shift + end/home respectively.
I find this useful for wrapping a line in curly braces/quotes/etc. whereas the other answers include spaces in the select so whatever you're wrapping it in will be wrapped around that whitespace.

Install the MetaGo extension and use the "metaGo: selectLineDown" command, which will come installed already overriding the "expandLineSelection" command.
This extension has many additional commands that you'll likely find useful as well, including moving up/down over code blocks, centering the active line, and going to any character on the screen.

Now, when I press Command+I, the whole line is selected. I am guessing this was caused by an update to VS Code, but I am not sure.

Ctrl + L on Windows or Command + L on Mac to select the whole line in VS Code.
You can use your mouse to select the whole line by triple-clicking on the line but the better way is to click on the line number to select the whole line or multiple lines.

Tripple click at any point on the line

In case you're wondering why Cmd+L is not working, there might be a chance that there are duplicate shortcuts. You can find out by opening Keyboard Shortcuts in VSC and remove the one that's not needed.

I know its old but for anyone seeking, you can press Alt + arrow up/down to duplicate your cursor to other lines and then without selecting anything copy and paste multiple lines.

Related

Is there a way to add a cursor to a specific line number in vs code without the mouse?

I really like the multiple cursor option in vs code.
With the mouse I can just Alt + Click any line I want to add a cursor to that specific line.
My question is if there is a way to do this with the key board? I have tried selecting current line and Ctrl + G to go to a specific line number, but then I lose my initial selection. I would like to have a cursor on the current line plus any line I choose at same time without using the mouse.
Does anyone know if this is possible? I tried a quick google search and searching here in SO, didn't see anything for this specifically.
Any help much appreciated!
With the extension Select By you can modify a Multi Cursor with the keyboard.

Is there a way to make VSCode Intellisense suggestions end outside the semicolon?

Intellisense suggestions are handy because I'm lazy, but any time I hit tab/enter to select one, it ends inside the ;. So then I have to arrow right and manually add a new line. Is there a setting or extension that autocompletes to outside the ; and optionally adds new line? or even just complete outside the semicolon. It's kind of cumbersome when writing many CSS rules to have to arrow right in between every line.
Vscodes native way to add a new line anywhere on a line is CTRL + Enter
You can add a new line above at any time using CTRL + SHIFT + Enter
You can try:
"editor.acceptSuggestionOnCommitCharacter": true,
Controls whether suggestions should be accepted on commit characters. For example, in JavaScript, the semi-colon (;) can be a commit character that accepts a suggestion and types that character

Turn multiline selection into multi cursor selection in VSCode

It happens from time to time that I need to edit 100+ lines in a text file all at once.
I know I can use ⌘ Cmd+↑/↓ to select multiple lines but depending on the size of the file that takes a while.
In Atom and Sublime, I can just do a ⌘ Cmd + a to select everything, hit another shortcut (forgot the actual shortcut) and end up with a cursor for every line.
Have not found this in VSCode.
Ctrl-a to select all. (or whatever muli-line selection you want)
Shift-alt-I will put cursors at end of each selected line.
And then if you want those cursors at the beginning of each line you need to trigger the command "cursorLineStart" which is unbound by default. Give it a keybinding and all those end-of-line cursors will jump to the beginning of each line.
With v1.43 and Column Selection Mode this can be quite easy, see Column selection like Visual Studio and How to put the cursor at the end of all selected lines in Visual Studio Code?
FWIW cursorLineStart is not the opposite of Shift-Alt-I. In looking at the commends, Shift-Alt-I is "Add cursors to line ends", but there is not a "Add cursors to line begins" option.
However, the easy trick for that is:
Select your text block
Shift-Alt-I to put a cursor at the end of each line
Command-LeftArrow will move those cursors to the beginning of the lines
Its an extra step but it works. When I get time I will play around with building a custom command to do all this in one action.

When selecting line in VS Code with the shortcut Ctr+i, cursor jumps to the line below. How to avoid it?

When selecting line in VS Code with the shortcut Ctr+i, the cursor jumps to the line below.
Meaning if i press copy, it actually copies two lines...
Is there a way to force the cursor to stay at the end of the selected line?
editor.action.smartSelect.grow
seems to do what you want with some number of keypresses unfortunately. It is already bound to Shift-Alt-RightArrow but you ca rebind that command to something else less cumbersome.

Automatic Code Identation

I have a huge code and now for testing purpose I have to add that whole script into an infinite while loop is there any short way (without pressing space for each row) to add a space for indentation so the whole code is consider part of the one while loop ? Such as for example when we press ctrl +r it comments out the line
Ctrl-I/Cmd-I will automatically indent the file. Other wse you just select multiple row and use Tab/Shift-Tab to move them backwards and forwards.
For indentation is a must, however Matlab as a language does not care so it is not really a must to indent it. Additionally, you can just execute the code from the command line, say that you script or function is called Umar, then from the command line you just type while 1, Umar; end.
You can copy the code into notepad++.
Activate Column mode selection holding alt+shift and use the mouse to select the column of all the text you want to insert a space/tabulation/etc. and just insert it.
Final step is to copy back the code to matlab.
Matlab does not currently support column selection.
MATLAB has the option to select all your code, then press the right click and select smart indent button.
If you like to use shortcuts, just type the combination of Ctrl+A (select all) followed by Ctrl+I (smart indent)