Some Visual Studio Tips and Tricks
Getting familiar with your IDE's shortcuts and capabilities can make you more productive. In this post we take a look at some tips and tricks for Microsoft's Visual Studio. Read on for more info!
Join the DZone community and get the full member experience.Join For Free
Editorial Note: I originally wrote this post for the SmartBear blog.
Last month, I wrote a post about integrated development environments (IDEs). As mentioned in that post, developers commonly debate the relative merits of lightweight text editors against heavyweight IDEs. But, I suspect just about everyone can agree that if you do plan to use an IDE, you should maximize its utility. In other words, as long as you’re incurring the overhead, you should reap the benefits.
I work a great deal in the .NET space, which means that I spend a good bit of time using Visual Studio, an extremely heavyweight IDE. In the interests of full disclosure, I will admit to loving to work with Visual Studio. But, that love has grown out of years of exploring it, tinkering with it, and learning to maximize my efficiency with it. If not for all that, it would seem only a glorified text editor that takes a lot longer than Notepad++ or Sublime to start.
Today, I’d like to offer some suggestions for getting more mileage out of Visual Studio. By no means is this an exhaustive list; that would require books and books, rather than a single blog post. Visual Studio has tons of capability. Rather, today, I’ll offer some tips and tricks you might not have seen previously.
Learn Your Keyboard Shortcuts
The first tip can apply beyond the world of Visual Studio, but it certainly applies to Visual Studio quite well. Learn your keyboard shortcuts.
Generally speaking, you’ll work more quickly and efficiently with hands on the keyboard than you will moving the mouse around to click on menus, sub-menus, and pop up screens. Start with the basics. Do you know how to compile, run, and debug? How about opening and creating new files?
But you can take this a lot further as well. For instance, do you know that keyboard shortcuts exist for the following functionality?
- Delete all breakpoints
- Cycle through multiple entries in the paste buffer
- Generate a method
- Surround code with (e.g. a try block)
- Perform a variety of automated refactorings
These exist for you to use, and a whole lot more besides. It’s worth exploring them, and I recommend trying to teach yourself at least one or two new ones per week to expand your repertoire.
Consider a Productivity Add-In
Impressive as the Visual Studio selection of shortcuts may be, there are third party vendors that specialize in making you more productive. Examples include CodeRush and ReSharper, two popular products in the .NET community. The tool authors focus their work exclusively on figuring out how to make software development more efficient. This includes significant interaction with the community.
More and more frequently these days, I see companies willing to purchase licenses for their entire development staff. That should tell you something about their effectiveness. If organizations happily spend thousands of dollars on these tools, clearly, they pay off in terms of your output.
Let’s now get a bit more specific with the tips. Visual Studio features a rich debugging experience that tends to make troubleshooting code much easier than you might otherwise find it. But below the surface of that experience lie some pretty cool advanced features.
One such feature is the breakpoint condition. Have you ever found yourself debugging while iterating over a collection, looking for an item with a specific property value? For instance, perhaps you have a gigantic collection of customer objects, but only want the debugger to stop for the one, somewhere in the list, with a specific social security number?
Do you simply break on every object, manually inspecting until you find the one you need? Or do you insert a little throw-away if condition and break inside that? You don’t need to do either.
Breakpoint conditions allow you to set a breakpoint, but only have it triggered if the condition you specify holds true. In our example, you could specify a condition of “customer.Social == 111-11-1111”, and stop only on that particular customer.
In more recent versions of Visual Studio, you can find the “quick launch” feature. You have probably noticed this bar in the upper left-hand corner of the IDE, but have you gotten full use out of it.
It provides you with a powerful ability, and one that made me absolutely ecstatic when I heard about it. You can do a text-based search for just about any feature or setting in Visual Studio. This excited me so much because of all of the years I had spent Googling which screen or menu housed some feature that I wanted to toggle. With quick launch, this struggle goes away.
Oh, and bearing in mind the first tip, you can access it easily with the keyboard shortcut Ctrl-Q.
In contrast to the quick launch bar, code snippets have been around for a while. With this feature, you have the ability to generate boilerplate code quickly, with only a few keystrokes.
For instance, perhaps you want to generate a try-catch-finally block or to declare an automatic integer property. Rather than laboriously typing all of this out, you can use code snippets to generate it quickly. Furthermore, you can manage the code snippets via the code snippet manager, including creating your own custom ones.
The last feature that I’ll mention is known as “peek definition.” To understand this, I will explain the problem that it solves.
When writing code or troubleshooting, I often feel frustrated by the need to switch between files. For instance, if I’m looking at a method and see a call to another class’s method, I need to open up a second file. If I’m lucky and have multiple monitors, I can view them side by side, but even that feels a bit clunky. With a single monitor, the friction really impedes reasoning about the code.
The peek definition feature provides a solution. When you activate it (Alt-F12 with your cursor on the target method), it overlays a small window into your current code window. In this fashion, you can view the two methods as though they were in the same class, sitting one on top of another.
Since the introduction of this feature into Visual Studio, I have found my experience significantly improved, particularly when reading for understanding.
As I mentioned at the outset, I have only scratched the surface of what you can do with this powerful IDE. I’ve listed some of the functionality I find most valuable and that I most highly recommend. But your mileage may vary.
By all means, try these features out if you have not already. But don’t forget to follow blogs, watch tutorials, and stay active in your community so that you can keep assimilating new tricks and efficiencies into your work.
Published at DZone with permission of , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.