Skip to content

Set default background color (:set bg&) after detecting terminal background color #869

@joshtriplett

Description

@joshtriplett

Vim's automatic background color detection works in GUI mode, but not in a terminal.

On any xterm-compatible terminal, vim could detect the background color via terminal escapes (documented in http://invisible-island.net/xterm/ctlseqs/ctlseqs.html) and use that to automatically detect whether to use bg=dark or bg=light (by default or with :set bg&).

To detect the background color:

  • Include `\e]11;?\a' during terminal initialization.
  • Asynchronously, when processing input, watch for the escape sequence \e]11;COLOR\a (or equivalent using OSC instead of \e] for the escape, and ST or \e\\ instead of \a for the terminator). If the COLOR portion matches rgb:RRRR/GGGG/BBBB where R, G, and B are hex digits, then compute the luminance of the RGB color and classify it as light/dark accordingly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions