Visual Studio C++ Productivity Tips
Table of Contents
Visual Studio is my main development environment. I’ve been using this tool probably since version 2003…2005. I am really happy that VS is getting more and more powerful these days and you can also use it on multiple-platforms (through VS Code, for web or cloud apps). What’s even better - it’s free for personal use or if you’re a small company (Community Version)! Today, I’ve prepared some productivity tips that might make your life a bit easier when developing an app in this Microsoft IDE.
I target native app development, but most of the rules should be generic to other languages as well.
Learn how to move in code
This is a very broad topic and probably the most important aspect on my list. When you learn programming you might work with simple projects with just several code files. In that scenario you have most of the code in your head. But, in a commercial projects you will end up with hundreds of files and classes. How to move efficiently is such complicated structures? You can easily forget about file hierarchy, let alone classes and subsystems.
Here are some basic steps:
Use go to definition/declaration
Probably, this is what I use the most often: switching between definition and declaration of a function, a variable or a class.
While you’re reading some code inside a method just by clicking on the
(F12, Ctr+Alt+F12) you can go to its declaration or vice
versa. Then, you can see where the function/method header is located,
what class it’s part of.
This works not only for methods or types, but also for variables/members: in a long method, you can just go to definition of some variable to see where it’s declared.
Possible problem: sometimes this feature does not work well for large projects :) Intellisense is from time to time stubborn and does not want to cooperate. But if you’re patient you’ll reach the target eventually. Also Intellisense is greatly improved with each version of Visual Studio.
Navigate to symbol
The most powerful thing: being able to navigate to anything you like.
Maybe you want to check a function? or a class declaration? or some
other symbol? In Visual Studio (Starting from version 2010) there is
“Navigate To” command:
Ctrl + COMMA
Enter the short-cut and then start typing a symbol name you want to check. VS will dynamically look for it and will give you a list of found items. You can easily navigate to a particular line in the code.
More about Navigate To:
I use that kind of navigation frequently. Sometimes I want to find something, but don’t know the proper type name. In that case I start typing some possible words that should match and usually I find what I was looking for.
In VisualAssist (described in the Plugins section) there is even more powerful tool: Find Symbol in Solution. This windows lets you quickly find any symbol in the solution, you can use prefixes, negative filters, multiple strings, etc.
See all references
This feature is very handy if you know what type/method you are looking for and you want to see where it’s being used. You can explore examples and recreate them in your solution.
At work, I often use this to track all the places that are related to some type/symbol. For example, when I need to add a similar type (some kind of a new attribute for a graphical element) I can search for all occurrences of some existing type and do the same for my new type: like recreate initialization, add to lists of supported types, register in UI, etc.
Recently, I’ve noticed that it might be nice to get something like “find some references”. This would be handy if you know that a function/code is used in hundreds of places (so search times might be huge), but you’re actually interested in any appearance, only a few would satisfy. This would work much faster. On the other hand, the IDE doesn’t know what items are most valuable to you… so it’s safer to return all the occurrences.
You might be also interested in using View Call Hierarchy feature, that shows calling hierarchy better that just finding all references.
Unfortunately, I must admit, I don’t have large RAM in my head and I
constantly forget where was I two minutes ago in the project :) Luckily,
I can navigate backwards and forwards to previously visited places -
Ctrl+ - and
Ctrl + Shift + -!
Alternatively, if you’re doing changes in two files, you can switch
between them by using
Ctrl+Tab. This will show the list of recently
used and open files so you can open it immediately.
There are also bookmarks that can be leveraged. You might mark important places of the code and switch between those places. Still, I don’t use them much often. Moving back and forth to recently visited places seems to be creating sort of natural bookmarks and you don’t have to remember additional shortcuts. On the other hand using bookmarks might be a good exercise.
- View Call Hierarchy - Finding all references of a function might be ok, but VS offers more advanced feature: Call Hierarchy. This shows what other functions called your original method.
- Class Hierarchy - Handy when you want to track what are the derived classes from you given class, or you want to track the common root of types. This feature is also connected to Object Browser.
- Switch between header and implementation file - another basic tool -
Ctrl+K, Ctrl+O. Especially useful when you write implementation of a class, and want to go to class declaration.
// TODO- Task List, mark important places in the code with
// TODO: textand then you can see them in Task List Window.
Bookmark one one this pages:
- MSDN Pre-defined Keyboard Shortcuts VS 2015
- Visual Studio 2015 keyboard shortcuts
Print it, keep it near your desk and learn those shortcuts daily.
Enable enhanced scroll bar
Every time I return to a simpler IDE that hasn’t enhanced scroll bar feature I am a bit lost. Enhanced scroll bar adds a huge boost to the way you can move in a file. In simple cases, you might remember where your method is located: is it at the beginning, near the middle or at the end of a file… that might work for some time. But the advanced scroll bar adds a map where you can find your code much faster. It creates a bigger picture and thus your brain can memorize where the code is ‘visually’ located in a file. No more random scrollbar searches! :)
Since most of lines have like 80…120 characters and you probably use a monitor with wide aspect ratio, then you should have some space on the right/left side in the editor. So even if you use very wide scrollbar it shouldn’t decrease the space for the code itself.
Also, the scrollbar shows some additional information like last modification, breakpoints, compiler errors and of course where is the currently edited line.
Read more about enhanced scroll bar at MSDN blog
Note that it’s great to have relatively small files. Otherwise your scrollbar map will just look like a normal, almost one colour, bar:
There is a chance to still get some value of such map, but the shorter the file the better in my opinion.
In Productivity Tools For VS2013 there is a addition called “Structure
Visualizer”. With “Show code structure in the margin” option you’ll get
a nice visualization of code blocks in a file.
Above image comes from official plugin site: visualstudiogallery/Productivity Power Tools 2013
Visual Studio is a very decent environment, but what if we could do better? Look for plugins that help with your daily tasks and fills some of the gaps that VS has.
I am a great fan of VisualAssist. For example, you can read some of my tips for this tool in my post from 2014: 3 Tools to Understand New Code from Visual Assist. VA is a complete set of tools for refactoring, code navigation, coding assistance… even debugging. Or to write this shortly: set of productivity tools.
Just take a look here:
It’s hard to tell when I am not using VA features - because it’s enabled all the time. But things like renaming a symbol name, extracting a method, class, documenting a function header, finding symbols, find base method declaration, class hierarchies… all of that are natural and really handy with VA. Also I am really impressed with the performance, rarely I need to wait for the results. As I mentioned before, you often need to wait for Intellisense, but with VA you don’t see such situations.
It’s not free (279$ for the full licence, 99$ for personal, 49$ for academic), but I highly encourage to save some money and buy the extension.
You can download the trial and have a quick look: Download a free trial.
ReSharper for C++
I’ve never used it, but always wanted :) I need to allocate some time and experiment with the trial version.
Resharper is a well known extension for .NET developers, but eventually the company was able to produce similar version for C++! It’s also a really large set of productivity tools.
BTW: here is the comparison (made by JetBrains): VisualAssist vs ReSharper for C++
In terms of pricing you can use several models, for example € 199.00 for first year, € 159.00 second, … or use some discounts.
Productivity Power Tools for VS
This time it’s a completely free set of tools that highly improve work with VS. Even if you have Visual Assist or ReSharper the plugin can still bring some value.
Here is the full list of features:
- Peek Help
- Solution Explorer Errors
- Structure Visualizer
- Double click to maximize windows
- Timestamp margin
- Quick tasks – Edit Present On
- Ctrl + Click to Peek Definition
- HTML Copy improvements
- Recently Closed Documents
- Match Margin
- Power Commands context menu cleanup
- Syntactic Line Compression
- Quick Tasks
- Power Commands
- Color printing
- Middle-Click Scrolling
- Organize Imports for Visual Basic
- Custom Document Well
- Tools Options Support
- HTML Copy
- Fix Mixed Tabs
- Ctrl + Click Go To Definition
- Align Assignments
- Column Guides
- Colorized Parameter Help
I especially like: Scrollbar markers (that shows additional code structure on the scrollbar), Recently Closed Documents, Document Tabs and some of the power commands.
Other interesting plugins
- AnkhSVN - Subversion Support - khSVN open source (free) Subversion SourceControl Provider.
- C++ Quick Fixes - VS 2015 only, add some help (in context menu) to fix some of the basic coding errors (like missing include, semicolon, using namespace, etc).
- VS10x CodeMAP - displays a graphical nested representation of the current code editor window (C#, VB, C++).
- Viasfora Add color to your Visual Studio Text Editor!
- Image Watch - Provides a watch window for visualizing in-memory images (bitmaps) when debugging native C++ code.
- Visual C++ Refactoring - VS 2013 only, in VS 2015 more refactoring features were added.
- GraphicalDebugging - VS 2015 only, the extension allows to view graphical representation of variables, e.g. Boost.Geometry models.
- IncrediBuild - IncrediBuild speeds up builds by distributing C#, C/C++ compilations and other tasks across machines in the local network.
Some more suggestions in this old StackOverflow question: Recommended add-ons/plugins for Microsoft Visual Studio
Like with every other tool practice is needed. Usually, after some time you’ll get used to any IDE and you find your own ways to be relatively productive. Still, this doesn’t mean it’s end of the story. Why not testing some other embedded tools, other techniques, key shortcuts, plugins, etc, etc… ?
Here are some suggestions for additional exercises for VS IDE:
- Try to minimize mouse usage, do most of the stuff using only keyboard.
- Learn one keyboard shortcut a day/week
- I mention that I don’t use bookmarks, but as an exercise I could use them for a day or two and then decide if it improves my workflow or not.
- Install ‘deep/large’ plugins like VisualAssist or ReSharper for C++ and (even trial versions) and play with them. Learn what tools and techniques do such plugins bring to the IDE.
- Use some other IDE! Do your pet project in some other IDE like QT Creator, Eclipse, etc, etc… or even use a command line + Vim. Maybe you’ll learn something that can be used in Visual Studio later?
Visual Studio is a very powerful IDE and it might be relatively hard to leverage all of its features. I hope that thanks to this article you’ve learn some techniques that will help when you work in the IDE. Since writing and reading code is probably the most often activity I think that ‘moving in code’ features are crucial to know. If you can quickly jump between files, locate classes, track variables, go to method definitions… (all via keyboard short-cuts of course! :)) then you can more focus on the actual job and not the problems with the tool.
I didn’t cover a lot of things: like build options, debugging, refactoring, windows layout, themes… maybe those are good topics for other articles. Let me know what would you like to read more.
- What are your tips for Visual Studio?
- Do you use some additional tools to work with this IDE?
- What is the most disappointing feature of VS?