Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>PowerShell - TextMate Scopes for Null OperatorsNew to Visual Studio Code? Get it now.
PowerShell - TextMate Scopes for Null Operators

PowerShell - TextMate Scopes for Null Operators

Bryan Cuneo

|
1 install
| (0) | Free
Adds TextMate scopes for PowerShell 7's null operators.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

PowerShell Null Operator Scopes

A VS Code extension that adds TextMate scopes for PowerShell 7's null operators.

Table of Contents

  • Null Operators
  • The Default Look
  • Usage Instructions
    • Installation
    • The Scopes
    • Where to put your highlighting rules
    • Highlight All the Same Color
    • Highlight Each Individually

Null Operators

PowerShell 7 has two null-coalescing operators and two null-conditional operators:

  • Null-coalescing operator - ??
  • Null-coalescing assignment operator - ??=
  • Null-conditional member operator - ?.
  • Null-conditional index operator - ?[]

Back to top

The Default Look

By default, VS Code's PowerShell extension's syntax highlighting does not enable direct styling of these operators. Here's how they look on the current default themes, Light 2026 and Dark 2026, and the PowerShell ISE theme that comes with Microsoft's PowerShell extension where these operators arguably look the worst:

defaults_and_ise

Back to top

Usage Instructions

This extension enables you to customize the colors of each operator on top of any existing color scheme. By creating entries in settings.json , it will override whatever scheme you're using and it will persist through scheme changes as well.

Back to top

Installation

This extension is available in the VS Code Extension Marketplace. You can also download the latest version and install it manually. Either graphically with Ctrl + Shift + P -> Developer: Install Extension from Location... or through the command line with:

code --install-extension /path/to/extension-version.vsix

Back to top

The Scopes

Operator Scope
?? keyword.operator.null-coalescing.powershell
??= keyword.operator.null-coalescing-assignment.powershell
?. keyword.operator.null-conditional-member.powershell
?[] keyword.operator.null-conditional-index.powershell

Back to top

Where to Put Your Highlighting Rules

In your settings.json file (Ctrl + Shift + P -> Preferences: Open User Settings (JSON)), add the following entry:

{
    // <your existing settings here...>

    "editor.tokenColorCustomizations": {
        "textMateRules": [
            // <your TextMate rules here>
        ]
    }
}

If you already have some editor.tokenColorCustomizations.textMateRules entries in your settings.json file, simply add new ones to the existing list.

Back to top

Highlight All the Same Color

If you want to highlight all of the null operators the same, simply combine all the scopes into one TextMate rule:

{
    "scope": "keyword.operator.null-coalescing-assignment.powershell, keyword.operator.null-coalescing.powershell, keyword.operator.null-conditional-member.powershell, keyword.operator.null-conditional-index.powershell",
    "settings": {
        "foreground": "#ff0000"
    }
}

That will highlight all of the null operators red: all_red

Note that you can combine them in any way you like. All 4 together, 2 and 2, highlight 3 but not a fourth, etc.

Back to top

Highlight Each Individually

If instead you wish to style them all separately, you can do that with these TextMate rules:

{ // ??
    "scope": "keyword.operator.null-coalescing.powershell",
    "settings": {
        "foreground": "#ff0000"
    }
},
{ // ??=
    "scope": "keyword.operator.null-coalescing-assignment.powershell",
    "settings": {
        "foreground": "#2fac4e"
    }
},
{ // ?.
    "scope": "keyword.operator.null-conditional-member.powershell",
    "settings": {
        "foreground": "#ff6600"
    }
},
{ // ?[]
    "scope": "keyword.operator.null-conditional-index.powershell",
    "settings": {
        "foreground": "#f760b5"
    }
}

This will highlight ?? red, ??= green, ?. orange, and ?[] pink:

individual_colors

Back to top

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft