VS Code Extensions
H

Header/Inline/Source Switch

by sneftel

Cycle between related C/C++ files in the same directory (e.g. .h -> .inl -> .cpp) with a single keystroke, skipping any that don't exist.

Downloads

7

Rating

— (0)

Version

0.3.0

Last updated

Jul 08, 2026

A tiny VS Code extension that cycles between related C/C++ files that share a base name in the same directory with a single keystroke — for example hkFoo.h -> hkFoo.inl -> hkFoo.cpp -> hkFoo.h.

Unlike the built-in "Switch Header/Source" (in the Microsoft C/C++ and clangd extensions), which only toggles between a header and a source file, this extension supports an ordered cycle of any number of extensions and works correctly when all of them are present. Extensions whose file does not exist are simply skipped.

Why

Codebases that keep inline definitions in .inl files (included from the .h) end up with three related files per unit. The stock Alt+O only knows about .h <-> .cpp, so you can never reach the .inl with a keystroke. This extension fixes that.

Usage

  • Alt+O — switch to the next existing related file in the cycle.
  • Shift+Alt+O — switch to the previous existing related file.

Both commands are also available from the Command Palette:

  • Switch to Next Related File (Header/Inline/Source)
  • Switch to Previous Related File (Header/Inline/Source)

The cycle wraps around, so from the last file you land back on the first. If no other related file exists, a brief status-bar message is shown and nothing happens.

The target file opens in preview mode. Because VS Code keeps a single preview tab per group, switching away from a preview tab reuses (closes) it, so cycling doesn't pile up tabs. If the target is already open as a pinned tab, the came-from preview tab is closed instead. Pinned (non-preview) files stay open.

Configuration

// settings.json
"headerInlineSourceSwitch.extensions": [".h", ".inl", ".cpp"]

The order defines the cycle direction. Extensions are matched case-insensitively and files must share the same base name and directory.

Resolving the Alt+O conflict

The Microsoft C/C++ extension also binds Alt+O. When two extensions bind the same key, VS Code's winner is not guaranteed. To make this extension's binding authoritative (and to disable the built-in one), add the following to your user keybindings.json (Command Palette -> "Preferences: Open Keyboard Shortcuts (JSON)"):

[
    {
        "key": "alt+o",
        "command": "headerInlineSourceSwitch.cycle",
        "when": "editorTextFocus && (resourceExtname == .h || resourceExtname == .inl || resourceExtname == .cpp)"
    },
    {
        // Disable the built-in C/C++ switch so it never wins the Alt+O race.
        "key": "alt+o",
        "command": "-C_Cpp.SwitchHeaderSource",
        "when": "editorTextFocus"
    }
]

If you use clangd instead, disable -clangd.switchheadersource the same way.

Installing from source

This extension is plain JavaScript with no build step.

  • Quick local install: package it with vsce:

    npm install -g @vscode/vsce
    vsce package
    code --install-extension header-inline-source-switch-0.3.0.vsix
    
  • Development: open this folder in VS Code and press F5 to launch an Extension Development Host.

License

MIT — see LICENSE.

Related extensions