CLion能否借助插件实现垂直拆分编辑器自动打开相关符号?
Absolutely! This is a super common workflow for C++ developers, and most modern IDEs/editors support this—either natively or via lightweight plugins. Let me walk you through how to set this up for the two most popular tools:
VS Code
- Install core extensions first: Make sure you have the Microsoft C/C++ Extension Pack installed—it provides the base C++ language support needed for file association logic.
- Add the auto-open plugin: Install the
Auto Open Related Fileextension from the marketplace. It’s designed specifically to handle this exact use case. - Configure the plugin to match your needs:
- Open Settings (
Ctrl+,on Windows/Linux,Cmd+,on Mac), search forAuto Open Related File. - Set
Auto Open Related File: Split Directiontoright(this ensures the related file opens in a vertical split adjacent to your current editor). - Verify
Auto Open Related File: Enabledis checked. - The plugin comes with default mappings for common C++ file pairs (.cpp ↔ .h ↔ .hpp), but if you use custom suffixes, you can add them in
Auto Open Related File: File Mapping(e.g.,{"cxx": ["hxx"], "hxx": ["cxx"]}).
- Open Settings (
Once set up, opening any .cpp file will automatically trigger a vertical split and load its corresponding header file (and vice versa) without you needing to manually use the Navigate -> Related Symbol command.
JetBrains IDEs (CLion, IntelliJ C++, etc.)
These IDEs have this functionality built-in—no plugins required:
- Open Settings (
Ctrl+Alt+Son Windows/Linux,Cmd+,on Mac). - Search for
Editor Tabs, then find theOpen related files in splitoption and check it. - Set the
Split directiondropdown toRightto get the vertical split layout you want. - Double-check file associations (usually already configured by default): Search for
File Types, then confirmC++ Source FilesandC++ Header Filesare linked correctly.
From now on, every time you open a C++ source or header file, its counterpart will automatically open in a vertical split next to it.
For Vim/Neovim users
You can achieve this with the vim-fswitch plugin. Add an autocmd to your .vimrc or init.lua to trigger a vertical split and open the related file whenever you open a C++ file:
autocmd BufReadPost *.cpp,*.h,*.hpp call fswitch#SwitchWithSplit('v')
内容的提问来源于stack exchange,提问作者Anton Krug

