DEV Community

Cover image for Productivity with Visual   Studio: Code Editor | Part 1
Fernando Sonego
Fernando Sonego

Posted on • Edited on

Productivity with Visual Studio: Code Editor | Part 1

In recent days we entered into a discussion with some friends and colleagues on how to increase productivity while developing applications. For my part, I suggested that the first thing we should do, before learning complex programming patterns or techniques, is to know perfectly with the tool we are working with. This made me think about doing a series of posts to see some tricks to increase our productivity with Visual Studio.

In this first part, we will see some tricks for the code editor, in future posts, we will see debugging, refactoring, and other quite interesting tricks. I recommend that these tricks make them part of your daily work.

Move lines up or down

We can select one or several lines of our code to move them up or down. It is as simple as selecting the lines and pressing alt plus the up or down key. alt+⬆️ alt+⬇️.

Move lines up or down

Select in the shape of a rectangle

It is very useful when we need to edit portions of code on multiple lines and multiple columns. We can activate it by pressing alt + shift and pressing the arrows.

Select in the shape of a rectangle

Edit multiple lines at once

Using the above functionality, alt + shift + arrows, we select a text and several lines and we will directly start typing. We will see that everything that was selected in the rectangle will begin to change as we type.

Edit multiple lines at once

Editing in multiple places at the same time

At some point, you surely needed to insert or edit the same text in different places. We can do this by choosing multiple entry points. We must hold down ctrl + alt, then, with the left mouse button, press in the places where we want to use as entry points. ctrl + alt + click.

Editing in multiple places at the same time

Selection of code blocks

Suppose we want to select code blocks for their closure, in C# for example {...}, standing inside we can use the key combination alt + shift + = to select outward if we want to make an inward select we will use alt + shift + -.

Selection of code blocks

Lowercase to uppercase to lowercase

Sometimes we have to change upper or lower case texts or vice versa. We can select the text and press ctrl + shift + u, for upper case and ctrl + u to make it lower case.

Lowercase to uppercase to lowercase

Expand, collapse and collapse our code

Visual Studio allows us to collapse, expand or contract our code depending on the language and the block closing structure, for example in C# es {..}. we always see that on the left side of the editor window the + or - to be able to do it with the mouse. It is also possible to do it with the key combination ctrl + m ctrl + m (collapses), ctrl + m ctrl + p (expands).

Expand, collapse and collapse our code

Code map

This is one of the most useful functionalities of the code editor in Visual Studio, also present in Visual Studio Code, it does not help to quickly position ourselves somewhere in our code file, especially if it is very extensive.

Code map

If we want to change the behavior of the bar we can do it from the Visual Studio configuration. We should go: Tools > Options > Text Editor > All Languages > Scroll Bars > Behavior.

Code map

Markers

Maybe the same thing happens to me, many times we have a large number of open files editing them at the same time. There are several ways to get from one place to another in the code, such as Go to the definition. Other times it is not possible. This is where bookmarks will be useful to us, we can put them in our lines of code to go from one place to another and they remain, although we close Visual Studio, they are:

Ctrl+K, Ctrl+K, put a marker.
Ctrl+K Ctrl+N, go to the next marker.
Ctrl+K Ctrl+P, go to the previous marker.
Ctrl+K Ctrl+L, clear all our bookmarks.

Markers

Multiple Clipboards

We copy a lot of code all the time, we copy something, then we copy another, we use it, but we also needed the old one. Visual Studio keeps a history of all the ctrl + c that we do while we are working. To access history we must stop at the place where we want to insert any of the codes copied previously and press ctrl + shift + v and the history will be displayed.

Multiple Clipboards

Conclusion

After these tips and practicing them a lot, we can increase our productivity. Remember, this is not simple at first, it takes practice and a good memory. Many of these functionalities are also present in the Visual Studio Code, so you can use them without problems. In future posts, we will see more tricks for Visual Studio that help us increase our Productivity.

Top comments (1)

Collapse
 
ronimeister profile image
Alexey Kanunnikov

Thanks a lot! Alt+Up would save me a whole bunch of time!