Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid multi cursor on wrapped lines in VS Code?

QUESTION:

I have turned on wordWrap in VSCode, so that lines are wrapped if I resize the window.

If I want to comment out some code or text, I usually just move the cursor to the beginning of the first line of the block of code, use ctrl+shift+down to add cursors, and type the // or # etc..

The problem with wordWrap is that I do not only get cursors in the beginning of each actual line, but in the beginning of every line as it is displayed at the moment in the editor.

Assume the document: 1 This is the first line. 2 Second line.

which might be wrapped as follows: 1 This is the first line. 2 Second line.

So if I use the method above and add % I would get: 1 %This is the first %line. 2 %Second line.

But what I want is the following: 1 %This is the first line. 2 %Second line.

Otherwise, I have a % in the middle of the line, just because I resize the editor window...

At the moment, I actually turn off wordWrap to achieve this, but I hope there is a better way?

PLEASE NOTE:

For adding comments, it is actually way simpler to use ctrl + / or shift + alt + a. But maybe the question is still interesting for other cases.

like image 367
Fabian Avatar asked Nov 13 '18 14:11

Fabian


People also ask

How do I disable multiple cursors in VS Code?

Right-click on each command that add a cursor and has a keyboard shortcut associated and select "Remove Keybinding". Also search for "Multi-Cursor". It could return the command "Toggle Multi-Cursor Modifier" that is associated to a combination of modifier keys (one or more of Ctrl , Alt , Shift ).


Video Answer


2 Answers

Follow the next steps:

  1. Alt+Shift+i to put a cursor on every selected line
  2. Cmd/Ctrl+ to move all cursors to the beginning of the [wrapped] lines
  3. Cmd/Ctrl+ (again) to move all cursors to the actual beginning of the [wrapped] lines

Enjoy! 🙂

like image 109
JavierCane Avatar answered Oct 10 '22 23:10

JavierCane


This appears to be a known issue. The CursorColumnSelectOnTrueLines extension by Martin Zimmermann provides commands that show the desired behavior, by default mapped to Ctrl+Alt+Shift+Up/Down.

like image 20
krlmlr Avatar answered Oct 11 '22 00:10

krlmlr