Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>dimNew to Visual Studio Code? Get it now.
dim

dim

Ufuktan Yıldırım

|
122 installs
| (0) | Free
Define regex rules to dim boring parts of code and make the main logic pop.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

dim

extension icon

Define rules to reduce opacity of repeating parts of code to make the main logic pop. Great for dimming Go's if err != nil { return fmt.Errorf(...) } error wrapping blocks and JavaScript's console.log calls.

Preview

Dim passes selections:

A screen recording of Visual Studio Code editor while the cursor is moved to show dimming is disabled whereever the user selects

Dim can be temporarily turned off for a document:

Dim on Go code and toggling feature

Example code are on Github Gist for JavaScript and on GitHub for Go. Themes are Gruvbox Material and Vitesse Black.

Features

  • Define rules based on standard regex patterns.
  • Supports optional regex flags. With sensible defaults, for those who are not comfortable with flags.
  • Matches both single line expressions and blocks of code.
  • Allows per-workspace rules via .vscode/config.json file, and per-language rules through language tags [js], [go], [json] etc.
  • Lets developers maintain high consistency of opacity values across every rule effortlessly by allowing them to assign only a opacity tier to rules. So, adjusting one tier's value is enough to update all rules using it.
  • Toggling (enabling/disabling) the extension per document: dim.toggleDimForCurrentEditor.
  • Dim respects carets. Means that Dim won't dim those areas that you are actively working on, or looking to.
  • Checks matched ranges to see if the number of opening { and closing } braces inside the matched block are equal to eliminate problems like partial dimming of blocks or dimming incomplete parts of the code. (Experimental)

Performance

Dim designed to work with high performance even in lower end machines.

  • No scroll hook. Some alternative extensions using scroll hook to apply decorations in visible ranges actually reduces the scroll performance in lower end machines. Dim performs scanning and applying decorations at document's first open, and after each content change with some delay.
  • Uses regex match on whole document rather than walking the document line by line to invoke regex engine at each line.
  • Robust editor lifecycle tracking. Dim tracks lifecycle updates that requires decoration updates or reusing same or different TextEditor instances for the document; does the needed and ignores the rest.
  • Dim merges the intersecting ranges of different rules with same opacity tier, to avoid applying multiple decorations on one sequence of text.
  • Dim is field tested for Code extension gotchas eg. constant feedback caused by applying decorations on log pane lead to infinite loop.
  • Dim lets you adjust the update period according to your needs and hardware through updatePeriod property. Lower values increase the responsiveness of extension and higher values are better for lower end hardware.
  • Dim reuses the same set of decorations per editor until the opacity values in config changes to avoid flickering issue which is enabled by performing decoration updates without requiring complete disposal of old ones.

Usage

{
    "[go]": {
        "dim.rules": [
            {
                "pattern": "if err != nil {.*?}",
                "flags": "gs",
                "opacity": "mid"
            },
            {
                // advanced version that forgives nested blocks and whitespaces
                "pattern": "if\\s+err != nil\\s*{(?:(?:[^{}]|\\n)*{(?:[^}]|\\n)*})?(?:[^}]|\\n)*}",
                "flags": "gs",
                "opacity": "mid"
            }
        ]
    },
    "[js]": {
        "dim.rules": [
            {
                "pattern": "announce\\(.*\\);?"
            },
            {
                "pattern": "logger\\.verbose\\([^\\n]*\\);?"
            }
        ]
    },
    "dim.rules": [
        {
            "pattern": "//.*", // comment lines
            "opacity": "max"
        }
    ],
    "dim.defaultFlags": "g",
    "dim.defaultOpacityTier": "min",
    "dim.valueForMinTier": 0.2,
    "dim.valueForMidTier": 0.3,
    "dim.valueForMaxTier": 0.4
}

Suggestions

  • Use proper escaping in pattern values; just like the examples above.
  • Use singleline regex mode (with s flag) for block dimming rules. See MDN page for regex flags or this Stackoverflow answer if you are not comfortable with the singleline mode.
  • Assign a keyboard shortcut for toggling Dim for current document
    {
        "key": "alt+cmd+h",
        "command": "dim.toggleDimForCurrentEditor"
    }
    

Contribution

Report bugs to encourage me to fix them since knowing people using this extension is the only way to do it.

  • Issues and PRs => https://github.com/ufukty/dim

Prior work

  • dim has inherited some code and logic from https://github.com/lorefnon/lowlight-patterns

License

  • See LICENSE file
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft