Home ยท Blog ยท Projects


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

ShortcutAction
Ctrl + SSave the current file
Ctrl + Shift + SSave As
Ctrl + K, Ctrl + CComment selected lines
Ctrl + K, Ctrl + UUncomment selected lines
Ctrl + ZUndo
Ctrl + YRedo
Ctrl + FFind in current file
Ctrl + HReplace in current file
Ctrl + Shift + FFind in Files
Ctrl + Shift + HReplace in Files
Ctrl + PGo to file / search files
Ctrl + TGo to All
F12Go to Definition
Alt + F12Peek Definition
Shift + F12Find All References
Ctrl + F12Go to Declaration
F5Start debugging
Ctrl + F5Start without debugging
Shift + F5Stop debugging
F9Toggle breakpoint
F10Step over
F11Step into
Shift + F11Step 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

ShortcutAction
Ctrl + PGo to a file
Ctrl + TGo to All
Ctrl + ,Go to All
Ctrl + GGo to line
F12Go to Definition
Ctrl + F12Go to Declaration
Alt + F12Peek Definition
Shift + F12Find All References
Ctrl + M, Ctrl + MCollapse/expand current code region

Go to All

Ctrl + T is particularly useful in C++ projects.

You can search for:

Example:

Ctrl + T
MyClass

This can be much faster than manually navigating through the Solution Explorer.


๐Ÿ”Ž Searching

Search in Current File

ShortcutAction
Ctrl + FFind
Ctrl + HReplace
F3Find next
Shift + F3Find previous

Search Across the Project

ShortcutAction
Ctrl + Shift + FFind in Files
Ctrl + Shift + HReplace in Files

Example

To find all usages of a CMake variable or C++ symbol:

Ctrl + Shift + F

Then search for:

MY_LIBRARY

or:

std::vector

This is useful when working with:


โœ๏ธ Editing C++

Comments

ShortcutAction
Ctrl + K, Ctrl + CComment selection
Ctrl + K, Ctrl + UUncomment selection

Example:

// int result = calculate();
// std::cout << result << '\n';

Select the lines and press:

Ctrl + K, Ctrl + C

Code Formatting

ShortcutAction
Ctrl + K, Ctrl + DFormat entire document
Ctrl + K, Ctrl + FFormat selected code

These are particularly useful when working with large C++ functions or after modifying CMake-generated code.

Format Document

Ctrl + K, Ctrl + D

Format Selection

Ctrl + K, Ctrl + F

๐Ÿงฉ Refactoring

ShortcutAction
Ctrl + .Quick Actions / Refactorings
F2Rename symbol
Shift + F12Find all references
F12Go to definition

Rename Symbol

Place the cursor on a C++ symbol and press:

F2

This is preferable to manually using Find & Replace because Visual Studio understands C++ symbols.

For example:

class MyClass {
public:
    void calculate();
};

Renaming:

calculate

can update its references throughout the project.


๐Ÿž Debugging

Debugging is one of the most important parts of a C++ workflow.

Starting and Stopping

ShortcutAction
F5Start debugging
Ctrl + F5Start without debugging
Shift + F5Stop debugging
Ctrl + Shift + F5Restart debugging

Start Debugging

F5

Visual Studio builds the required targets and starts the debugger.

Run Without Debugger

Ctrl + F5

Useful when you only want to run the application without debugger overhead.


๐Ÿ›‘ Breakpoints

ShortcutAction
F9Toggle breakpoint
Ctrl + F9Enable/disable breakpoint
Ctrl + Alt + BOpen Breakpoints window

Example:

int result = calculateValue();  // F9

Press:

F9

to create a breakpoint on the current line.


๐Ÿชœ Stepping Through Code

ShortcutAction
F10Step Over
F11Step Into
Shift + F11Step Out
Shift + F5Stop debugging

Step Over

F10

Executes the current line without entering a called function.

Step Into

F11

Enters the called function.

Example:

int result = calculate();

Pressing F11 will enter:

calculate()

Step Out

Shift + F11

Leaves the current function and returns to the caller.


๐Ÿง  Debugging C++

Useful windows during debugging:

ShortcutAction
Ctrl + Alt + W, 1Watch 1
Ctrl + Alt + W, 2Watch 2
Ctrl + Alt + V, AAutos
Ctrl + Alt + V, LLocals
Ctrl + Alt + CCall Stack
Ctrl + Alt + BBreakpoints

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:

The following shortcuts are useful regardless of the underlying build configuration.

Build

ShortcutAction
Ctrl + Shift + BBuild Solution
Ctrl + Alt + F7Rebuild Solution
Ctrl + BreakCancel build

Build

Ctrl + Shift + B

Use this frequently after modifying:


โš™๏ธ CMake Configuration

When changing CMake configuration, it can be useful to distinguish between:

CMake configuration
        โ†“
CMake generation
        โ†“
Build
        โ†“
Run / Debug

For example:

CMakeLists.txt
      โ†“
Configure
      โ†“
Generate build system
      โ†“
Build target
      โ†“
F5

Visual 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

ShortcutAction
Ctrl + Alt + LSolution Explorer
Ctrl + Alt + OOutput
Ctrl + Alt + MError 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

ShortcutAction
Ctrl + \, EError List
Ctrl + Alt + OOutput
F8Next error
Shift + F8Previous error

After a CMake or compiler failure, check:

Error List

and especially:

Output

The 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

ShortcutAction
Ctrl + SpaceTrigger IntelliSense
Ctrl + JList members
Ctrl + Alt + SpaceToggle IntelliSense completion mode
EscClose completion list

Trigger IntelliSense

Ctrl + Space

Useful when IntelliSense does not automatically display suggestions.


๐Ÿ“– Documentation & Code Understanding

ShortcutAction
F12Go to Definition
Alt + F12Peek Definition
Shift + F12Find All References
Ctrl + QSearch Visual Studio

For unfamiliar C++ code, a useful workflow is:

Find symbol
    โ†“
F12
    โ†“
Inspect implementation
    โ†“
Shift + F12
    โ†“
Inspect usages

๐ŸชŸ Windows & Panels

ShortcutAction
Ctrl + Alt + LSolution Explorer
Ctrl + Alt + OOutput
Ctrl + Alt + MError List
Ctrl + Alt + CCall Stack
Ctrl + Alt + BBreakpoints
Ctrl + Alt + W, 1Watch 1
Ctrl + Alt + V, LLocals

๐Ÿงน Code Folding

ShortcutAction
Ctrl + M, Ctrl + MToggle current region
Ctrl + M, Ctrl + OCollapse to definitions
Ctrl + M, Ctrl + LToggle all outlining
Ctrl + M, Ctrl + ACollapse all

These shortcuts are useful for navigating large .cpp and .hpp files.


๐Ÿ“ Multiple Cursors & Selection

ShortcutAction
Alt + ClickAdd cursor
Ctrl + Alt + .Add next matching occurrence
Ctrl + DDuplicate 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

ShortcutAction
Ctrl + CCopy
Ctrl + XCut
Ctrl + VPaste
Ctrl + ZUndo
Ctrl + YRedo
Ctrl + DDuplicate line
Shift + DeleteDelete line
Alt + UpMove line up
Alt + DownMove 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 + T

2. Understand a symbol

F12

3. Find where it is used

Shift + F12

4. Modify and format

Ctrl + K, Ctrl + D

5. Build

Ctrl + Shift + B

6. Debug

F5

7. Step through the code

F10
F11
Shift + F11

8. 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             โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•