Visual Studio Hotkeys for CMake & C++ Development
A practical cheat sheet for the most useful Visual Studio keyboard shortcuts when working on C++ projects with CMake.
Note: These shortcuts refer primarily to the default Visual Studio key bindings on Windows. Some shortcuts may differ if you use a custom keyboard mapping or a different Visual Studio configuration.
๐ฅ Most Important Shortcuts
| Shortcut | Action |
|---|---|
Ctrl + S | Save the current file |
Ctrl + Shift + S | Save As |
Ctrl + K, Ctrl + C | Comment selected lines |
Ctrl + K, Ctrl + U | Uncomment selected lines |
Ctrl + Z | Undo |
Ctrl + Y | Redo |
Ctrl + F | Find in current file |
Ctrl + H | Replace in current file |
Ctrl + Shift + F | Find in Files |
Ctrl + Shift + H | Replace in Files |
Ctrl + P | Go to file / search files |
Ctrl + T | Go to All |
F12 | Go to Definition |
Alt + F12 | Peek Definition |
Shift + F12 | Find All References |
Ctrl + F12 | Go to Declaration |
F5 | Start debugging |
Ctrl + F5 | Start without debugging |
Shift + F5 | Stop debugging |
F9 | Toggle breakpoint |
F10 | Step over |
F11 | Step into |
Shift + F11 | Step out |
๐งญ Navigation
Fast navigation is especially useful in large C++/CMake projects where headers, source files, CMake files, and generated code are spread across many directories.
Files and Symbols
| Shortcut | Action |
|---|---|
Ctrl + P | Go to a file |
Ctrl + T | Go to All |
Ctrl + , | Go to All |
Ctrl + G | Go to line |
F12 | Go to Definition |
Ctrl + F12 | Go to Declaration |
Alt + F12 | Peek Definition |
Shift + F12 | Find All References |
Ctrl + M, Ctrl + M | Collapse/expand current code region |
Go to All
Ctrl + T is particularly useful in C++ projects.
You can search for:
- Classes
- Functions
- Variables
- Files
- Types
- CMake files
- Symbols
Example:
Ctrl + T
MyClassThis can be much faster than manually navigating through the Solution Explorer.
๐ Searching
Search in Current File
| Shortcut | Action |
|---|---|
Ctrl + F | Find |
Ctrl + H | Replace |
F3 | Find next |
Shift + F3 | Find previous |
Search Across the Project
| Shortcut | Action |
|---|---|
Ctrl + Shift + F | Find in Files |
Ctrl + Shift + H | Replace in Files |
Example
To find all usages of a CMake variable or C++ symbol:
Ctrl + Shift + FThen search for:
MY_LIBRARYor:
std::vectorThis is useful when working with:
CMakeLists.txt.cmakefiles.cpp.hpp.h.cc.cxx
โ๏ธ Editing C++
Comments
| Shortcut | Action |
|---|---|
Ctrl + K, Ctrl + C | Comment selection |
Ctrl + K, Ctrl + U | Uncomment selection |
Example:
// int result = calculate();
// std::cout << result << '\n';Select the lines and press:
Ctrl + K, Ctrl + CCode Formatting
| Shortcut | Action |
|---|---|
Ctrl + K, Ctrl + D | Format entire document |
Ctrl + K, Ctrl + F | Format selected code |
These are particularly useful when working with large C++ functions or after modifying CMake-generated code.
Format Document
Ctrl + K, Ctrl + DFormat Selection
Ctrl + K, Ctrl + F๐งฉ Refactoring
| Shortcut | Action |
|---|---|
Ctrl + . | Quick Actions / Refactorings |
F2 | Rename symbol |
Shift + F12 | Find all references |
F12 | Go to definition |
Rename Symbol
Place the cursor on a C++ symbol and press:
F2This is preferable to manually using Find & Replace because Visual Studio understands C++ symbols.
For example:
class MyClass {
public:
void calculate();
};Renaming:
calculatecan update its references throughout the project.
๐ Debugging
Debugging is one of the most important parts of a C++ workflow.
Starting and Stopping
| Shortcut | Action |
|---|---|
F5 | Start debugging |
Ctrl + F5 | Start without debugging |
Shift + F5 | Stop debugging |
Ctrl + Shift + F5 | Restart debugging |
Start Debugging
F5Visual Studio builds the required targets and starts the debugger.
Run Without Debugger
Ctrl + F5Useful when you only want to run the application without debugger overhead.
๐ Breakpoints
| Shortcut | Action |
|---|---|
F9 | Toggle breakpoint |
Ctrl + F9 | Enable/disable breakpoint |
Ctrl + Alt + B | Open Breakpoints window |
Example:
int result = calculateValue(); // F9Press:
F9to create a breakpoint on the current line.
๐ช Stepping Through Code
| Shortcut | Action |
|---|---|
F10 | Step Over |
F11 | Step Into |
Shift + F11 | Step Out |
Shift + F5 | Stop debugging |
Step Over
F10Executes the current line without entering a called function.
Step Into
F11Enters the called function.
Example:
int result = calculate();Pressing F11 will enter:
calculate()Step Out
Shift + F11Leaves the current function and returns to the caller.
๐ง Debugging C++
Useful windows during debugging:
| Shortcut | Action |
|---|---|
Ctrl + Alt + W, 1 | Watch 1 |
Ctrl + Alt + W, 2 | Watch 2 |
Ctrl + Alt + V, A | Autos |
Ctrl + Alt + V, L | Locals |
Ctrl + Alt + C | Call Stack |
Ctrl + Alt + B | Breakpoints |
The exact shortcuts for debugging windows can depend on the selected Visual Studio keyboard mapping.
๐๏ธ CMake & Build Workflow
When working with CMake projects in Visual Studio, the exact build commands depend on whether you use:
- CMake Project support
- CMakePresets
- Visual Studio-generated solutions
- Ninja
- MSBuild
The following shortcuts are useful regardless of the underlying build configuration.
Build
| Shortcut | Action |
|---|---|
Ctrl + Shift + B | Build Solution |
Ctrl + Alt + F7 | Rebuild Solution |
Ctrl + Break | Cancel build |
Build
Ctrl + Shift + BUse this frequently after modifying:
.cpp.hppCMakeLists.txt.cmake- compiler settings
- project configuration
โ๏ธ CMake Configuration
When changing CMake configuration, it can be useful to distinguish between:
CMake configuration
โ
CMake generation
โ
Build
โ
Run / DebugFor example:
CMakeLists.txt
โ
Configure
โ
Generate build system
โ
Build target
โ
F5Visual Studio provides CMake-specific commands through the CMake menu and CMake integration.
Useful general shortcuts:
Ctrl + Shift + B Build
F5 Debug
Ctrl + F5 Run๐งญ Solution Explorer
| Shortcut | Action |
|---|---|
Ctrl + Alt + L | Solution Explorer |
Ctrl + Alt + O | Output |
Ctrl + Alt + M | Error List |
Solution Explorer is useful for navigating the generated project structure, although Ctrl + T is often faster for locating a specific C++ file or symbol.
โ ๏ธ Errors and Build Output
| Shortcut | Action |
|---|---|
Ctrl + \, E | Error List |
Ctrl + Alt + O | Output |
F8 | Next error |
Shift + F8 | Previous error |
After a CMake or compiler failure, check:
Error Listand especially:
OutputThe Output window is often more useful for CMake problems because it can contain the actual compiler, linker, CMake, or build-system command that failed.
๐งฑ C++ Code Completion
| Shortcut | Action |
|---|---|
Ctrl + Space | Trigger IntelliSense |
Ctrl + J | List members |
Ctrl + Alt + Space | Toggle IntelliSense completion mode |
Esc | Close completion list |
Trigger IntelliSense
Ctrl + SpaceUseful when IntelliSense does not automatically display suggestions.
๐ Documentation & Code Understanding
| Shortcut | Action |
|---|---|
F12 | Go to Definition |
Alt + F12 | Peek Definition |
Shift + F12 | Find All References |
Ctrl + Q | Search Visual Studio |
For unfamiliar C++ code, a useful workflow is:
Find symbol
โ
F12
โ
Inspect implementation
โ
Shift + F12
โ
Inspect usages๐ช Windows & Panels
| Shortcut | Action |
|---|---|
Ctrl + Alt + L | Solution Explorer |
Ctrl + Alt + O | Output |
Ctrl + Alt + M | Error List |
Ctrl + Alt + C | Call Stack |
Ctrl + Alt + B | Breakpoints |
Ctrl + Alt + W, 1 | Watch 1 |
Ctrl + Alt + V, L | Locals |
๐งน Code Folding
| Shortcut | Action |
|---|---|
Ctrl + M, Ctrl + M | Toggle current region |
Ctrl + M, Ctrl + O | Collapse to definitions |
Ctrl + M, Ctrl + L | Toggle all outlining |
Ctrl + M, Ctrl + A | Collapse all |
These shortcuts are useful for navigating large .cpp and .hpp files.
๐ Multiple Cursors & Selection
| Shortcut | Action |
|---|---|
Alt + Click | Add cursor |
Ctrl + Alt + . | Add next matching occurrence |
Ctrl + D | Duplicate line/selection |
Shift + Alt + . | Select next occurrence |
Multiple cursors can be useful for repetitive changes in CMake files.
Example:
target_compile_definitions(app PRIVATE
FEATURE_A
FEATURE_B
FEATURE_C
)๐ Clipboard & Line Editing
| Shortcut | Action |
|---|---|
Ctrl + C | Copy |
Ctrl + X | Cut |
Ctrl + V | Paste |
Ctrl + Z | Undo |
Ctrl + Y | Redo |
Ctrl + D | Duplicate line |
Shift + Delete | Delete line |
Alt + Up | Move line up |
Alt + Down | Move line down |
Moving lines is especially useful when reorganizing CMake targets or C++ initialization lists.
๐งฐ Useful CMake Workflow
A practical workflow for a CMake-based C++ project can look like this:
1. Open project
โ
2. Ctrl + T
โ
3. Find CMakeLists.txt / source file
โ
4. Edit code
โ
5. Ctrl + K, Ctrl + D
โ
6. Ctrl + Shift + B
โ
7. Fix compiler errors
โ
8. F9
โ
9. F5
โ
10. F10 / F11
โ
11. Inspect variables / call stackโญ Recommended Daily Shortcuts
If you only want to memorize a small set, start with these:
Ctrl + T Go to All
Ctrl + F Find
Ctrl + Shift + F Find in Files
F12 Go to Definition
Shift + F12 Find All References
F2 Rename Symbol
Ctrl + . Quick Actions
Ctrl + K, Ctrl + C Comment
Ctrl + K, Ctrl + U Uncomment
Ctrl + K, Ctrl + D Format Document
Ctrl + Shift + B Build
F5 Debug
Ctrl + F5 Run without Debugging
F9 Toggle Breakpoint
F10 Step Over
F11 Step Into
Shift + F11 Step Out
Ctrl + Alt + O Output
Ctrl + Alt + L Solution Explorer
Ctrl + Alt + M Error List๐ Recommended C++/CMake Productivity Workflow
For everyday development, the following shortcuts cover most tasks:
1. Find code
Ctrl + T2. Understand a symbol
F123. Find where it is used
Shift + F124. Modify and format
Ctrl + K, Ctrl + D5. Build
Ctrl + Shift + B6. Debug
F57. Step through the code
F10
F11
Shift + F118. Inspect problems
Ctrl + Alt + O
Ctrl + Alt + M๐ Quick Reference
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ VISUAL STUDIO C++ / CMAKE โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฃ
โ NAVIGATION โ
โ Ctrl + T Go to All โ
โ F12 Go to Definition โ
โ Shift + F12 Find References โ
โ F2 Rename Symbol โ
โ โ
โ EDITING โ
โ Ctrl + K, Ctrl + C Comment โ
โ Ctrl + K, Ctrl + U Uncomment โ
โ Ctrl + K, Ctrl + D Format Document โ
โ Ctrl + . Quick Actions โ
โ โ
โ SEARCH โ
โ Ctrl + F Find โ
โ Ctrl + H Replace โ
โ Ctrl + Shift + F Find in Files โ
โ โ
โ BUILD โ
โ Ctrl + Shift + B Build โ
โ Ctrl + F5 Run โ
โ F5 Debug โ
โ โ
โ DEBUGGING โ
โ F9 Breakpoint โ
โ F10 Step Over โ
โ F11 Step Into โ
โ Shift + F11 Step Out โ
โ โ
โ WINDOWS โ
โ Ctrl + Alt + L Solution Explorer โ
โ Ctrl + Alt + O Output โ
โ Ctrl + Alt + M Error List โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ