Skip to content

24-bit color not restored correctly on Windows #5092

@lzybkr

Description

@lzybkr

Describe the bug

If the terminal uses 24-bit color before starting vim, the colors are not restored correctly.
This happens because vim uses screen scraping to save the screen and those legacy console apis do not support 24-bit color.
One possible fix is to use the alternate screen buffer. I tried this myself and it seems to work. It also seems to be what the Linux version of vim does as the problem does not reproduce if you run vim from WSL.

To Reproduce
Detailed steps to reproduce the behavior:

  1. Ensure the terminal displays some 24-bit color, e.g. run this PowerShell script
  2. Run vim.exe
  3. Exit

Expected behavior
The screen is restored without colors changing.

Screenshots
Before:
image

After:
image

Environment (please complete the following information):

  • Vim version 8.1
  • OS: Windows 10 1903
  • Terminal: Windows Terminal

Additional context
My screen shots demonstrate a possible (minimally tested) fix. I'm guessing a better fix is possible though, maybe using a non-Windows code path.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions