2

Visual Studio useful editor shortcuts

 1 year ago
source link: https://mariusbancila.ro/blog/2020/08/05/visual-studio-useful-editor-shortcuts/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Visual Studio useful editor shortcuts

Posted on August 5, 2020 by Marius Bancila

The Visual Studio editor has lots of functionalities, many of them available with the use of shortcuts. In this post, I will share several that I find very useful and I use quite often. This post refers to Visual Studio 2019.

Vertical selection

You can perform vertical selection (of columns) by either pressing the ALT key and using the mouse to select, or pressing SHIFT + ALT and using the arrow keys to select. This is useful when you have code vertically aligned and need to make some repetitive changes. For instance, here is an example with replacing -> with a dot.

verticalselection.gif

Multiple carets

Sometimes you may need to make similar changes in multiple places. This is possible by using multiple carets. There are different ways to do this.

One way is to insert a caret automatically to:

  • all matches of a token, with SHIFT + ALT + ;
  • the next match of a token, with SHIFT + ALT + .
multicaret.gif

Another way is to insert multiple carets at desired locations by pressing CTRL + ALT and clicking with the mouse cursor.

multicaret2.gif

Commenting and uncommenting

It is possible to comment or uncomment the current line or selection with the following key combinations:

  • CTRL + K followed by CTRL + C to comment
  • CTRL + K followed by CTRL + U to uncomment

comment.gif

Moving lines

Sometimes you may need to change the order of some lines (such as the order of some variable declaration, or order of properties defined in a JSON file). You can move the current line one position down with SHIFT + ALT + T.

moveline.gif

Formatting

You can use CTRL + K, CTRL + F to apply formatting to the current selection (according to the settings from Tools | Options | Text Editor).

formatting.gif

Increasing/decreasing selection of code blocks

You may find it is useful to expand selection to the enclosing block. It’s possible with the mouse, paying attention to what you select. But it’s also possible to use the keyboard for this. You can use SHIFT + ALT + + to increase the selection to the next logical block, and SHIFT + ALT + - to decrease it.

selection.gif

Word transposing

Although perhaps not as commonly needed as the previous features, this feature allows to change the order of the two words that follow the cursor. This can be a very helpful feature if you are a C++ developer that adhered to the East const style, and want to change text such as const int a to int const a. Although this functionality is not available through a pre-defined shortcut, you can register one from Tools | Options | Environment | Keyboard.
wordtranspose.gif

Others

There are many more useful shortcuts, and here are some articles that can help you learning them:
Default keyboard shortcuts in Visual Studio
Visual Studio shortcut keys
Improving your productivity in the Visual Studio Editor
15 Tips and Tricks to Increase Your Productivity in Visual Studio 2019

If you don’t like a particular shortcut or you want to assign a shortcut to a feature that does not have a default one, you can do so from Tools | Options | Environment | Keyboard.

shortcuts.png

Like this:

Loading...

CategoriesTools, Visual StudioTagsIDE, Visual Studio, VS2019


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK