Multi-line copies from tmux scrollback buffer strips newlines #18351

Closed
opened 2026-01-31 06:11:12 +00:00 by claunia · 5 comments
Owner

Originally created by @mrjoel on GitHub (Sep 1, 2022).

Windows Terminal version

1.14.2281.0

Windows build number

10.0.19044.0

Other Software

tmux 3.3a-1~bpo11+1 (inside WSL2, from Debian bullseye-backports)

Steps to reproduce

  • From within a tmux session, execute something which generates multiple terminal heights in output
  • Working path
    • from Terminal, select to copy some multi-range text at the bottom of output
    • paste text into target application of choice, note that newlines are preserved - good
  • Error path
    • enter scrollback mode in tmux, scroll up to earlier output
    • from Terminal, select to copy some multi-range text towards the top of the output
    • paste text into target application of choice, note that all newlines are stripped and the output is combined as a single long line - bad

Scrolling up a full page or more is the easiest way to observe this, but careful observation shows that when scrolling less than a page up the scrollback buffer (so some originally viewable text is retained), copying the text that was originally viewable retains newlines, while copying text retrieved from the scrollback buffer strips the newlines. In fact, doing a multi-line selection across the boundary of original view pane results in stripped newlines only up until the original viewable content is encountered, at which point newlines are retained.

Expected Behavior

Copying multi-line selections through Terminal always retains newlines, even from alternate buffer and tmux scrollback buffer

Actual Behavior

New lines are stripped from multi-line selection copied text

Originally created by @mrjoel on GitHub (Sep 1, 2022). ### Windows Terminal version 1.14.2281.0 ### Windows build number 10.0.19044.0 ### Other Software tmux 3.3a-1~bpo11+1 (inside WSL2, from Debian [bullseye-backports](https://packages.debian.org/bullseye-backports/tmux)) ### Steps to reproduce * From within a tmux session, execute something which generates multiple terminal heights in output * Working path * from Terminal, select to copy some multi-range text at the bottom of output * paste text into target application of choice, note that newlines are preserved - good * Error path * enter scrollback mode in tmux, scroll up to earlier output * from Terminal, select to copy some multi-range text towards the top of the output * paste text into target application of choice, note that all newlines are stripped and the output is combined as a single long line - bad Scrolling up a full page or more is the easiest way to observe this, but careful observation shows that when scrolling less than a page up the scrollback buffer (so some originally viewable text is retained), copying the text that was originally viewable retains newlines, while copying text retrieved from the scrollback buffer strips the newlines. In fact, doing a multi-line selection across the boundary of original view pane results in stripped newlines only up until the original viewable content is encountered, at which point newlines are retained. ### Expected Behavior Copying multi-line selections through Terminal always retains newlines, even from alternate buffer and tmux scrollback buffer ### Actual Behavior New lines are stripped from multi-line selection copied text
claunia added the Issue-BugResolution-Duplicate labels 2026-01-31 06:11:12 +00:00
Author
Owner

@EBADBEEF commented on GitHub (Sep 2, 2022):

There are a few fuzzy things that probably need to be described. I have been pulling my hair out on this one too...

  • Do you have "Automatically copy selection to clipboard" (copyOnSelect)?
  • Do you have mouse support enabled in tmux?
  • Follow-up, do you hold shift while selecting selecting the text (to avoid tmux grabbing the mouse click)?
  • How exactly are you copying? Right mouse button, ctrl+insert, ctrl+shift+c? Are you holding shift while clicking the right mouse button?
  • What version of windows ("ver" command) and terminal? (for me it's win 10.0.22000.856, terminal 1.14.2282.0) (edit: I see you already provided that info)

In my testing, holding shift while right clicking always strips out the newlines, even in a cmd.exe shell!

If I select the text with shift+lmb then copy with the keyboard shortcut everything is good. Also, doing a block select works (holding alt+shift).

@EBADBEEF commented on GitHub (Sep 2, 2022): There are a few fuzzy things that probably need to be described. I have been pulling my hair out on this one too... - Do you have "Automatically copy selection to clipboard" (copyOnSelect)? - Do you have mouse support enabled in tmux? - Follow-up, do you hold shift while selecting selecting the text (to avoid tmux grabbing the mouse click)? - How exactly are you copying? Right mouse button, ctrl+insert, ctrl+shift+c? Are you holding shift while clicking the right mouse button? - What version of windows ("ver" command) and terminal? (for me it's win 10.0.22000.856, terminal 1.14.2282.0) (edit: I see you already provided that info) In my testing, holding shift while right clicking *always* strips out the newlines, even in a cmd.exe shell! If I select the text with shift+lmb then copy with the keyboard shortcut everything is good. Also, doing a block select works (holding alt+shift).
Author
Owner

@mrjoel commented on GitHub (Sep 2, 2022):

Do you have "Automatically copy selection to clipboard" (copyOnSelect)?
Do you have mouse support enabled in tmux?
Follow-up, do you hold shift while selecting selecting the text (to avoid tmux grabbing the mouse click)?

Yes, yes, and yes

How exactly are you copying? Right mouse button, ctrl+insert, ctrl+shift+c? Are you holding shift while clicking the right mouse button?

I hold shift and select with the left mouse button. Once text is selected, copyOnSelect does its thing and I paste in my destination of choice. In order to copy again, I have to press Esc to clear the previous selection and then again hold shift and select with left mouse button.

Anything with the right mouse button attempts to paste copied content.

@mrjoel commented on GitHub (Sep 2, 2022): > Do you have "Automatically copy selection to clipboard" (copyOnSelect)? > Do you have mouse support enabled in tmux? > Follow-up, do you hold shift while selecting selecting the text (to avoid tmux grabbing the mouse click)? Yes, yes, and yes > How exactly are you copying? Right mouse button, ctrl+insert, ctrl+shift+c? Are you holding shift while clicking the right mouse button? I hold shift and select with the left mouse button. Once text is selected, `copyOnSelect` does its thing and I paste in my destination of choice. In order to copy again, I have to press `Esc` to clear the previous selection and then again hold shift and select with left mouse button. Anything with the right mouse button attempts to paste copied content.
Author
Owner

@EBADBEEF commented on GitHub (Sep 3, 2022):

I guess my issue is different, then! If you search through the terminal issues for "paste" you will find tons of problems about newlines. But out of solidarity I tried to reproduce your issue :-). I installed a fresh debian in WSL. First I tried stretch tmux (2.3-4) but failed to reproduce. Then I added bullseye-backports to /etc/apt/sources.list and updated:

deb http://deb.debian.org/debian bullseye-backports main contrib non-free
deb-src http://deb.debian.org/debian bullseye-backports main contrib non-free
$ sudo apt update && sudo apt upgrade

My debian-foo is rusty so I'm not really sure how you got 3.3a-1~bpo11+1 installed into stretch. I assume you build it from source? So I tried:

$ apt source -t bullseye-backports tmux
$ sudo apt build-dep -t bullseye-backports tmux
--> failed with  "builddeps:tmux : Depends: debhelper-compat (= 13) but it is not installable"
$ sudo apt install debhelper libevent-dev libncurses5-dev libutempter-dev pkg-config build-essential
$ cd tmux-3.3a
$ dpkg-buildpackage
--> failed with same debhelper-compat error
(so I manually built)
$ ./configure --enable-utempter && make

How I tried to reproduce:

  • My ~/.tmux.conf contains just set-option -g mouse on
  • Changed my windows terminal to enable copyOnSelect
  • I started tmux and generated pages of output with while [ 1 ]; do echo -e 'line1\nline2\nline3'; done
  • I entered scrollback mode with ctrl-B + [, scrolled up with pgup (see something like [672/1850] in the corner)
  • Copied multiple lines with shift + left mouse button drag
  • Hit ctrl-c to leave tmux scrollback mode
  • Typed echo '<PASTE>' | xxd and see the newlines are in the output correctly (not necessary to use xxd, but it is easy to spot runs of 20s).
  • My TERM before entering tmux is xterm-256color, inside tmux is screen-256color
  • My shell is bash
  • I do note that our Windows and Windows Terminal versions are different.
  • Sometimes I get garbled output when looking at my echo command line + paste in bash, but the output is correct. Weird. Looks like line1> line3.

The only time I got added spaces was when I accidentally copied the line counter where tmux prints [n/total] in the upper right corner. Hah! I tried mixing alternate screen and not by doing lots of echo then entering a long man page (man iptables) and then scrolling back up to the prints in tmux. But still no luck.

Maybe make a video? You can record pretty quickly with xbox game bar (win+g key). Good luck!

@EBADBEEF commented on GitHub (Sep 3, 2022): I guess my issue is different, then! If you search through the terminal issues for "paste" you will find tons of problems about newlines. But out of solidarity I tried to reproduce your issue :-). I installed a fresh debian in WSL. First I tried stretch tmux (2.3-4) but failed to reproduce. Then I added bullseye-backports to /etc/apt/sources.list and updated: ``` deb http://deb.debian.org/debian bullseye-backports main contrib non-free deb-src http://deb.debian.org/debian bullseye-backports main contrib non-free $ sudo apt update && sudo apt upgrade ``` My debian-foo is rusty so I'm not really sure how you got 3.3a-1~bpo11+1 installed into stretch. I assume you build it from source? So I tried: ``` $ apt source -t bullseye-backports tmux $ sudo apt build-dep -t bullseye-backports tmux --> failed with "builddeps:tmux : Depends: debhelper-compat (= 13) but it is not installable" $ sudo apt install debhelper libevent-dev libncurses5-dev libutempter-dev pkg-config build-essential $ cd tmux-3.3a $ dpkg-buildpackage --> failed with same debhelper-compat error (so I manually built) $ ./configure --enable-utempter && make ``` How I tried to reproduce: - My ~/.tmux.conf contains *just* `set-option -g mouse on` - Changed my windows terminal to enable copyOnSelect - I started tmux and generated pages of output with `while [ 1 ]; do echo -e 'line1\nline2\nline3'; done` - I entered scrollback mode with `ctrl-B + [`, scrolled up with pgup (see something like [672/1850] in the corner) - Copied multiple lines with shift + left mouse button drag - Hit ctrl-c to leave tmux scrollback mode - Typed `echo '<PASTE>' | xxd` and see the newlines are in the output correctly (not necessary to use xxd, but it is easy to spot runs of 20s). - My TERM before entering tmux is `xterm-256color`, inside tmux is `screen-256color` - My shell is bash - I do note that our Windows and Windows Terminal versions are different. - Sometimes I get garbled output when looking at my echo command line + paste in bash, but the output is correct. Weird. Looks like `line1> line3`. The only time I got added spaces was when I accidentally copied the line counter where tmux prints `[n/total]` in the upper right corner. Hah! I tried mixing alternate screen and not by doing lots of `echo` then entering a long man page (`man iptables`) and then scrolling back up to the prints in tmux. But still no luck. Maybe make a video? You can record pretty quickly with xbox game bar (win+g key). Good luck!
Author
Owner

@zadjii-msft commented on GitHub (Sep 8, 2022):

Pretty sure this looks like /dup #8976

edit: yes it definitely is

@zadjii-msft commented on GitHub (Sep 8, 2022): Pretty sure this looks like /dup #8976 edit: yes it definitely is
Author
Owner

@ghost commented on GitHub (Sep 8, 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 (Sep 8, 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#18351