How to Edit multiple lines in Visual studio 2017 at once
Asked Answered
S

8

37

I'm following a series of videos on Youtube on how to develop a dashboard using bootstrap. The developer in that series uses the Sublime Text editor.

I've noticed that sometimes he clicks on multiple places (one after another) then start typing, and whatever he's typing appears on all these places. I think that saves a lot of time.

In VS and SSMS, one can press ALT then select a rectangle that will be modified. But this one is different as you can just select randomly several places, then start typing.

Do we have the same functionality in Visual Studio 2017?

Satisfactory answered 16/3, 2017 at 14:40 Comment(4)
Have you tried this extension: marketplace.visualstudio.com/…Feckless
Depends on the project you are coding but if you can use VSCode then that supports multiple insertion points.Babar
As of the current version, alt+click works!Photomechanical
There some easy ways: meziantou.net/…Malleable
E
47

You can use Shift+Alt while left clicking, but that will only be good for multiple lines selection

Elgar answered 22/4, 2018 at 10:44 Comment(0)
S
34

The question might be dated but in Visual Studio 2019 while holding down

Ctrl + Alt

click the lines that you want to change and it works as you wanted.

Sande answered 23/11, 2019 at 10:3 Comment(0)
S
9

As @besthost and @Noel Nemeth commented, you can use ALT + SHIFT

Another option is keeping ALT pressed and select the lines you want with mouse.

Smite answered 24/4, 2019 at 11:55 Comment(1)
ALT is what I was looking for. Thanks!Lonnalonnard
P
6

You can do this in Visual Studio Code, since it is based on Atom. In VS2017, I believe you can only do Select+ALT block editing. I would expect to see features from Code/Atom continue to migrate to VS in the future.

Padget answered 1/12, 2017 at 0:27 Comment(2)
Visual Studio Code is based on Electron, Atom is also based on Electron. Electron is JS framework that can create an executable out of JS application.Yellowhammer
That's correct, Electron is a JS framework for creating cross-platform desktop applications.Padget
P
1

The shortcuts changes over the versions of VisualStudio. If any of answers already provided doesn't work for you, you can always check shortcut in Visual Studio options.

Tools -> Environment -> Keyboard

keyboard options

Preadamite answered 6/12, 2022 at 8:54 Comment(0)
K
0

On mac you can also use cmd + d + d after highlighting certain part of code, and then whatever you type will be reflected to rename in multiple places.

Kancler answered 30/6, 2021 at 19:33 Comment(0)
N
-2

In Version 1.26.1 (1.26.1) of Visual Studio code you can edit multiple lines:

var donut 1 = "glazed"; 
var donut 2 = "chocolate frosted"; 
var donut 3 = "cinnamon";

go to each location (ie to the right side of the last character ) and hit "Alt" + "spacebar" . It will insert a " | ". When all the lines have a | (the character above the backslash) inserted then the cursor > will is controlling all these lines.

////////////// Example One ///////////////////////////

If we type a , the , will be inserted on all the lines simultaneously.

var donut 1 = "glazed";| 
var donut 2 = "chocolate frosted";|
var donut 3 = "cinnamon";|

////////////// Example Two ///////////////////////////

lines. If we hit the backspace key, all three lines will have characters > to the right side of the " | " will be deleted on all the lines simultaneously.

var donut 1 = |"glazed"; 
var donut 2 = |"chocolate frosted";
var donut 3 = |"cinnamon";

To insert the | character in the line, position the cursor and hit "Alt" + "spacebar"

Neckline answered 29/8, 2018 at 5:10 Comment(1)
Thanks, that's interesting. The question was about Visual Studio though, not about Visual Studio Code. https://mcmap.net/q/53704/-what-are-the-differences-between-visual-studio-code-and-visual-studioIndemnify
R
-3

As far as I'm aware you can't. I wanted to find out the same thing a while ago and from what I read online, you can't with Visual Studio. You'll need a plugin that adds extra functionality.

To do this in Sublime Text, you need to press Ctrl (Windows) or Cmd (Mac) and click to select multiple lines or columns.

Rheingold answered 16/3, 2017 at 14:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.