VS2017代码块纯色背景标记及整行无空白选中问题咨询
Nice set of questions! Let's break down how to solve both of your requirements in Visual Studio 2017:
Solution for Requirement a) Persistent Solid Background Markers for Code Blocks
If you want to mark a code block with a solid background that stays visible even after moving your cursor, here are your best options:
- Use a dedicated Visual Studio extension: Grab
Code Highlighterfrom the Visual Studio Marketplace. Once installed, just select your target code block, right-click, and choose a persistent highlight color. The background will stay put no matter where your cursor moves. - Leverage your existing Visual Assist: You might have missed this feature in Visual Assist. Open its options via the
VAssistXmenu >Options, then navigate toHighlighting > Custom Highlighting. Click "Add" to create a new rule: set it to apply to your selected code (or define a specific pattern), pick your desired solid background color, and check the "Persistent" box. This will keep the highlight active even when you move away from the code block. - Built-in bookmarks (quick workaround): If you prefer not to use extensions, add bookmarks at the start and end of your code block (use
Ctrl+K, Ctrl+Kto toggle bookmarks). Then go toTools > Options > Environment > Fonts and Colors, find the "Bookmark" or "Bookmark Margin" entries, and adjust their background colors to make the block stand out. Note this marks individual lines rather than filling the entire block's background, but it's a quick built-in fix.
Solution for Requirement b) Full-Column Selection Background (No Gaps)
To get selection backgrounds that cover the entire width of each line (from the first to last column, with no gaps in empty spaces), try these steps:
- Tweak Visual Studio's built-in coloring: Navigate to
Tools > Options > Environment > Fonts and Colors. Look for the "Selected Text" entry—by default, this only highlights the actual text, but you can adjust its background color here. Also, set the "Selection Margin" entry (in the same list) to a matching color. This will make the entire line appear highlighted when you select a code block. - Use a full-line selection extension: Install an extension like
Full Line Selection. This overrides the default selection behavior to highlight the entire width of each selected line, including blank spaces, exactly what you're looking for. - Adjust Visual Assist settings: Again, Visual Assist can solve this. Go to
VAssistX > Options > Editor > Selection, look for an option like "Full Line Selection" or "Extend selection to line ends" and enable it. This will make your selections cover the full column range without leaving gaps in statement whitespace.
内容的提问来源于stack exchange,提问作者Maverick
相关产品推荐
相关产品推荐

