Turn multiline selection into multi cursor selection in VSCode - visual-studio-code

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.

Related

Is there an equivalent shortcut in RStudio of the Ctrl + D command in VS Code?

The Command + D or Ctrl + D (in Windows) keybinding in VS Code allows you to add the next occurrence of a selected portion of code to your current selection.
Is there an equivalent in RStudio?
There isn't an equivalent shortcut, but you can get cursors on all occurrences by pressing Cmd/Ctrl F, then selecting "All" matches:
You might be looking for the Find and Add Next command that is available in the RStudio Keyboard Shortcuts Menu.
For selecting single words it works without initial selection as well.
Simply place your cursor somewhere on the current word, press Cmd+D (or whatever keybinding you have assigned) and it first selects the current word and then consecutively adds the next word occurence to the selection.
To my knowledge there is currently no way to skip an occurrence and continue the same selection afterwards nor to go backwards and consecutively add previous occurences to the selection whereas both of these are possible in Visual Studio Code.

How to highlight multiple words on VIM and modify them all? Like CTRL+D does on VS-Code?

On VSCode, if you highlight a text, you can do "CTRL+d" and it will highlight the next matching text and add a cursor there.
You can then start typing/deleting and it will affect all the cursors.
How can I do this in VIM?
Note: I know the search and replace function, this is too slow to type, is there something as easy or almost as easy as it is on VSCode?
:%s/foo/bar
Visual explanation on VSCode:
Highlight the word you're looking to replace:
CTRL+d two times, which highlights them all:
Now modify them all at the same time:
I want this will help you.
You can do the below steps to change all selected words.
< SHIFT > + # // select the all words on your cursor.
:%s//NEW_WORD/g
If you want to change all 'const' to 'AAA',
move to one of the 'const' words and press < SHIFT >+'#'.
And type the command ":%s//AAA/g".
Move the cursor on top of a word in your code.
Type gb to add another cursor. This puts Vim into Visual
mode and ready to operate on the word you have selected.
Type gb to continue adding cursors until you’re done.
Now you can perform an action in Visual mode (delete,
change, etc).
Go back to Normal mode with <ESC>

How to select whole line in VSCode

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.

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)