vim pollutes terminal history buffer #17079

Closed
opened 2026-01-31 05:31:39 +00:00 by claunia · 2 comments
Owner

Originally created by @adriantaga on GitHub (Mar 25, 2022).

Windows Terminal version

1.12.10394.0

Windows build number

10.0.18363.1556

Other Software

vim 8.1 inside WSL1 ubuntu 20.04
vim 8.2 inside WSL2 alpine 3.15
vim 8.2 inside cygwin
vim 8.2 on debian bullhead over ssh from inside WSL

Steps to reproduce

Short description: After moving around files in vim under wt, the history buffer becomes polluted with the contents of the edited file.

I have not experienced this problem when using other terminals like cmd.exe, mintty.exe or FluentTerminal.

  1. Open a WSL or a cygwin tab where vim is available. Run any commands that produce plenty of output, so that you have someting in the history buffer to scroll up to.
  2. Check that your TERM env var has the default value, xterm-256color. If not, reset it.
    $ export TERM=xterm-256color
  3. Open a file with vim. Chose a file that is sufficiently large so that it cannot all fit on the screen.
  4. Move around in the file by using pgdn/pgup/CTRL+F/CTRL+B. These commands jump a screen at a time. Commands that jump less than that, for example CTRL+D/CTRL+U, do not trigger this bug.
  5. Quit vim
  6. Scroll up (using mouse wheel or ctrl+shift+pgup) and check the contents of your terminal history.

Expected Behavior

Terminal history should be preserved.

Actual Behavior

vim restores the contents of the screen that's immediately visible, but parts of the edited file are left behind in the terminal history and become visible by scrolling up.

Investigating the cause

When using a different TERM, for example screen-256color, the problem does not occur.
So it appears that wt is not interpreting correctly some xterm-256color control sequences.

I managed to narrow down the problem to a single terminfo capability, clear.
It's value for screen-256color is \E[H\E[J
It's value for xterm-256color is \E[H\E[2J
I suspect wt can correctly handle the first, but not the second. Changing this one value fixed the history polution problem for me.

To quickly check that this is indeed the case, try running:

$ tic <(infocmp -w1 xterm-256color | sed 's/^xterm/wt/;s/clear=.*/clear=\\E[H\\E[J,/')
$ export TERM=wt-256color

The first command creates a new terminal definition called wt-256color, by using xterm-256color as the starting point and changing the value of the clear capability.

Originally created by @adriantaga on GitHub (Mar 25, 2022). ### Windows Terminal version 1.12.10394.0 ### Windows build number 10.0.18363.1556 ### Other Software vim 8.1 inside WSL1 ubuntu 20.04 vim 8.2 inside WSL2 alpine 3.15 vim 8.2 inside cygwin vim 8.2 on debian bullhead over ssh from inside WSL ### Steps to reproduce Short description: After moving around files in vim under wt, the history buffer becomes polluted with the contents of the edited file. I have not experienced this problem when using other terminals like cmd.exe, mintty.exe or FluentTerminal. 1. Open a WSL or a cygwin tab where vim is available. Run any commands that produce plenty of output, so that you have someting in the history buffer to scroll up to. 2. Check that your TERM env var has the default value, xterm-256color. If not, reset it. `$ export TERM=xterm-256color` 3. Open a file with vim. Chose a file that is sufficiently large so that it cannot all fit on the screen. 4. Move around in the file by using pgdn/pgup/CTRL+F/CTRL+B. These commands jump a screen at a time. Commands that jump less than that, for example CTRL+D/CTRL+U, do not trigger this bug. 5. Quit vim 6. Scroll up (using mouse wheel or ctrl+shift+pgup) and check the contents of your terminal history. ### Expected Behavior Terminal history should be preserved. ### Actual Behavior vim restores the contents of the screen that's immediately visible, but parts of the edited file are left behind in the terminal history and become visible by scrolling up. ### Investigating the cause When using a different TERM, for example screen-256color, the problem does not occur. So it appears that wt is not interpreting correctly some xterm-256color control sequences. I managed to narrow down the problem to a single terminfo capability, `clear`. It's value for screen-256color is `\E[H\E[J` It's value for xterm-256color is `\E[H\E[2J` I suspect wt can correctly handle the first, but not the second. Changing this one value fixed the history polution problem for me. To quickly check that this is indeed the case, try running: ``` $ tic <(infocmp -w1 xterm-256color | sed 's/^xterm/wt/;s/clear=.*/clear=\\E[H\\E[J,/') $ export TERM=wt-256color ``` The first command creates a new terminal definition called wt-256color, by using xterm-256color as the starting point and changing the value of the `clear` capability.
claunia added the Issue-BugResolution-Duplicate labels 2026-01-31 05:31:39 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Mar 28, 2022):

Pretty sure this is /dup #381. Thanks!

@zadjii-msft commented on GitHub (Mar 28, 2022): Pretty sure this is /dup #381. Thanks!
Author
Owner

@ghost commented on GitHub (Mar 28, 2022):

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost commented on GitHub (Mar 28, 2022): Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#17079