Visual Studio is full of shortcuts and handy tools helping you, as a programmer, to be more efficient in your work. Today I'm sharing a few of my favourite ones. All examples given here are tested in Visual Studio 2012.
- Open search result in a list
F to open the search pane. Enter your search string and then next to the find button you can open alternative search ways and select
Besides taking you to the first occurrence of the text searched for, Visual Studio also opens a
Find Results window (normally at the bottom) with all the occurrences of the search phrase.
In this window you can click through all locations and at the bottom you'll also get some statistics of what has been found.
Another way of doing this search is to press
F and click on the
Find All button in the dialog that opens.
- Find active document in Solution Explorer
Using menu options like “Go to definition” is great. But sometimes you’re taken to a document and you have no idea where the document belongs, especially if you have plenty of projects. By clicking on the
Sync with Active Document button (see picture below), Solution Explorer will navigate to the location where the current document exists and mark it.
It might sound a bit strange to have a hard coded break in your code but it can be useful for testing purposes. Breakpoints are very handy but they can be easily turned off, while this line of code has to be removed to prevent debugger from stopping. An example is shown here:
Debugger class can be found in the
- Cut the line
If you mark a text and press
X that text will be cut. But if you don’t mark any text and press the same
X the whole line (including carriage return) will be cut. You can also press
L to cut the whole line without the carriage return.
- Move line up or down
ALT while pressing
down and you’ll move the current line up or down.
CTRL while you’re using the wheel on your mouse and you can easily zoom in and out as needed.
- Auto format the document
Are you facing a document with a lot of wrong indentations? Press
D to format the whole document. If you only want to format a smaller selection then select the code and press
F. If you open the menu
Text Editor you can adjust how Visual Studio is going to do this formatting.
- Select vertically and update all lines at once
ALT while you’re selecting a code snippet. You’ll then be able to do a vertical selection instead of line by line selection. Funky, right?
But it doesn’t stop there. You can also do a simultaneous update of all the lines you’ve marked. In the example below we’re able to change all variables at once from private to public.
- Scroll with arrow keys without moving marker
CTRL while pressing
down and you’ll scroll the window while keeping the marker at the same position. The effect is equal to using the scroll wheel on the mouse or the scroll bar at the side of the window, but you need the mouse to do both of them while this is a key-only option.
- View all open windows in a list
TAB to open this overview window. You can then move around using the
TAB key or the arrows. Very convenient!
More tips and tricks for Visual Studio can be found at these places:
Johan is the CEO of BJ Focus Ltd
, a UK company specialised in the development of business structure platforms helping companies to structure flows of organisable data.
He writes articles on the BJ Lab's blog
, especially when his customers keep asking the same thing. You might find a few of these articles here on CodeProject.
Currently his focus is on building MVC web apps on the Azure platform, but PHP and MySQL get their share of attention as well.
Johan has double masters, in business and in software development, and an MCTS in .Net Framework 4, web applications.