如何在Visual Studio的Solarized配色方案中单独修改C++关键字及括号颜色?
Hey there! I totally get the frustration of trying to tweak specific syntax bits in a great theme like Solarized without messing up the rest of your setup. Let’s break down how you can target just those C++ keywords (if, while, etc.) and brackets without touching other elements.
Method 1: Use Visual Studio’s Built-in C++ Specific Syntax Settings
This is the simplest way if you don’t need ultra-fine control:
- Open
Tools > Options > Environment > Fonts and Colors - In the "Show settings for" dropdown, pick Text Editor
- Scroll through the "Display items" list to find these C++-exclusive entries:
- C++ Keyword: This is exactly for keywords like
if,while,for, andelse. Change its "Item foreground" color, and it’ll only affect C++ code—no other languages will be touched. - C++ Braces / C++ Parentheses: These target
{}and()respectively. If you want to adjust the highlight when your cursor is on a matching bracket, look for Brace Matching (Highlight) (make sure it’s scoped to C++ if the option exists).
- C++ Keyword: This is exactly for keywords like
Method 2: Edit the Theme’s .vssettings File (Precise Control)
If the built-in settings don’t split elements the way you want (like separating small brackets from curly braces), you can manually edit the theme file:
- Go to
Tools > Import and Export Settings, choose "Export selected environment settings", check Fonts and Colors, and export to a.vssettingsfile. - Open the file in a text editor (like VS Code or Notepad++) and search for the
<Category name="Text Editor">section. - Look for entries like:
Replace the hex color values (the<Item name="C++ Keyword" Foreground="FFB58900" ... /> <Item name="C++ Braces" Foreground="FF839496" ... />FFxxxxxxpart) with your desired colors. - Save the file, then import it back via
Tools > Import and Export Settingsto apply your customizations.
Method 3: Use a Third-Party Extension (Visual, No XML Hassle)
If manual XML editing sounds tedious, grab the Color Theme Editor for Visual Studio (it’s an official Microsoft extension):
- Install it from the Visual Studio Extensions Marketplace.
- Open
Tools > Customize Colors, select your Solarized theme as the base. - On the left, expand the C/C++ section under "Syntax Items". You’ll see all the specific elements like keywords, braces, and parentheses—just click to change their colors, then save your modified theme.
A quick note: After making changes, restart Visual Studio to ensure everything takes effect. Also, if you’re on VS 2022, some item names might be slightly different, but just look for entries with the C++ prefix and you’ll be good to go.
内容的提问来源于stack exchange,提问作者HalloweenJack

