Visual Studio 2019 Tricks

Today we are going to look at different tricks or techniques that will help us when programming with Visual Studio.

1 - Code Map in Visual Studio

This feature lets us visualize code quickly while we are inside a file, next to the vertical scroll bar.

To enable it, go to Tools -> options -> text editor -> All languages and within this menu, check “use map mode for vertical scroll bar”.

visual studio code map

2 - Automatically Comment Code

When we comment code, we usually do it manually, either by using double slashes // or the slash-asterisk to close /**/

/*public CsvWriter()
{
    ListContent = new List<T>();
}*/

//public CsvWriter(List<T> content)
//{
//    AssignContent(content);
//}

We can do this automatically by selecting the lines we want to comment and pressing Ctrl + K, C

If we want to uncomment the code, press Ctrl + K, U

3 - Locate the Current File in Visual Studio

It's common that when we use the feature to search all files in the project for a particular word, and we find it in the file we want, we have no idea where that file is in the directory tree.

To avoid searching manually, Visual Studio includes a feature that lets us find it automatically. Once we are in the file, simply press Ctrl + [, S and the file explorer will highlight that file.

Alternatively, you can use the two-arrow icon, one pointing to each side, which locates the file for you.

locate file visual studio

 

 

4 - Bookmarks in Visual Studio

A feature that almost no one uses, but can be very valuable while programming, is bookmarks.

Bookmarks are indicated in Visual Studio by the bookmark icon.

bookmarks visual studio

To add a bookmark, press Ctrl + K, K

Visual Studio also lets us use the bookmark window by pressing Ctrl + K, W or, alternatively, View -> Bookmark window

Inside the bookmarks window, we can perform different actions such as navigating between them, grouping them by folder, and more.

bookmark view visual studio 2019

 

 

5 - Simultaneous Line Editing in Visual Studio

A less commonly used feature is modifying multiple lines at once. To do this, press Shift + Alt + Click on each line you want to modify, and Visual Studio will add a cursor to each one.

 

 

6 - Preview Feature

Previewing a file can be very helpful, especially if you are looking for something and are not sure where it is.

The preview function will open the file temporarily, only while it is selected in the Solution Explorer.

To activate the preview function, press this icon once at the top of Solution Explorer.

preview visual studio

Once you are in preview mode, you can click the small icon inside the tab, or edit the file to turn it into a full tab and stop being in preview mode.

convert preview to tab

 

 

7 - Paste Special in Visual Studio

By default, Visual Studio includes a very useful feature that lets you create classes directly from a JSON or XML.

To do this, copy a JSON, for example the following:

{"menu": {
  "id": "file",
  "value": "File",
  "popup": {
    "menuitem": [
      {"value": "New", "onclick": "CreateNewDoc()"},
      {"value": "Open", "onclick": "OpenDoc()"},
      {"value": "Close", "onclick": "CloseDoc()"}
    ]
  }
}}

Then go to the menu edit -> paste special -> Paste JSON As Classes

paste special

and it will automatically generate the necessary classes.

public class Rootobject
{
    public Menu menu { get; set; }
}

public class Menu
{
    public string id { get; set; }
    public string value { get; set; }
    public Popup popup { get; set; }
}

public class Popup
{
    public Menuitem[] menuitem { get; set; }
}

public class Menuitem
{
    public string value { get; set; }
    public string onclick { get; set; }
}

 

 

8 - Move Class to a New File

This example ties in closely with the previous one. Commonly, when we are programming, we create classes or DTOs all together in a single file, and it becomes a bit tedious to create a separate file for each one. For this reason, Visual Studio offers a feature that lets you move a class to its own file.

To do this, place the cursor over the class name and press Ctrl +. which will open the quick actions menu.

move type to file.cs

If you click on the first option, you'll see it says “move type to Menu.cs”. In this way, Visual Studio creates the corresponding file for that class.

 

This post was translated from Spanish. You can see the original one here.
If there is any problem you can add a comment bellow or contact me in the website's contact form

Uso del bloqueador de anuncios adblock

Hola!

Primero de todo bienvenido a la web de NetMentor donde podrás aprender programación en C# y .NET desde un nivel de principiante hasta más avanzado.


Yo entiendo que utilices un bloqueador de anuncios como AdBlock, Ublock o el propio navegador Brave. Pero te tengo que pedir por favor que desactives el bloqueador para esta web.


Intento personalmente no poner mucha publicidad, la justa para pagar el servidor y por supuesto que no sea intrusiva; Si pese a ello piensas que es intrusiva siempre me puedes escribir por privado o por Twitter a @NetMentorTW.


Si ya lo has desactivado, por favor recarga la página.


Un saludo y muchas gracias por tu colaboración

© copyright 2025 NetMentor | Todos los derechos reservados | RSS Feed

Buy me a coffee Invitame a un café