Line breaks are ignored inconsistently when copying text in tmux copy mode #12335

Closed
opened 2026-01-31 03:12:46 +00:00 by claunia · 16 comments
Owner

Originally created by @antoineco on GitHub (Jan 31, 2021).

Environment

Windows build number: 10.0.19042.746
Windows Terminal version: 1.6.10272.0 (current Preview version from Microsoft Store)

Ubuntu WSL distribution from the Microsoft Store: 2004.2020.812.0
tmux: 3.0a (from Ubuntu's APT package repo)

Steps to reproduce

1. Open a WSL terminal

2. Run a new tmux session:

$ tmux

3. Generate some output. Here a sample output from the command I ran while running into this, for your convenience

$ cat <<EOF
Install Kubernetes apps from helm charts or YAML files using the "install"
command.

You can also find the post-install message for each app with the "info"
command.

Usage:
  arkade install [flags]
  arkade install [command]

Aliases:
  install, i

Examples:
  arkade install
  arkade install openfaas  --gateways=2
  arkade install inlets-operator --token-file $HOME/do-token
EOF

4. Press Enter multiple times, until the output disappears from the current window.

5. Enter tmux's copy mode with Ctrl-B [

Note: first Ctrl-B, then [. Not simultaneously

6. Scroll up with arrow keys or PgUp

7. Copy the previously generated output.

8. (optional) Press q to exit tmux's copy mode.

image

Expected behavior

The copied text contains line breaks at the end of each line.

In this case, I'm expecting:

You can also find the post-install message for each app with the "info"
command.

Usage:
  arkade install [flags]
  arkade install [command]

Aliases:
  install, i

Actual behavior

This is the raw pasted text. Notice the spaces before "Aliases" instead of the new line (I can replicate the issue with any text, not only that one):

You can also find the post-install message for each app with the "info"
command.

Usage:
  arkade install [flags]
  arkade install [command]
                                                                                                                                                            Aliases:
  install, i

ℹ️ Important note: this happens only in tmux's copy mode. After pressing q, copying the same output will work as expected.

Originally created by @antoineco on GitHub (Jan 31, 2021). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. If this is an application crash, please also provide a Feedback Hub submission link so we can find your diagnostic data on the backend. Use the category "Apps > Windows Terminal (Preview)" and choose "Share My Feedback" after submission to get the link. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment Windows build number: `10.0.19042.746` Windows Terminal version: `1.6.10272.0` (current Preview version from Microsoft Store) Ubuntu WSL distribution from the Microsoft Store: `2004.2020.812.0` tmux: `3.0a` (from Ubuntu's APT package repo) # Steps to reproduce 1\. Open a WSL terminal 2\. Run a new tmux session: ```console $ tmux ``` 3\. Generate some output. _Here a sample output from the command I ran while running into this, for your convenience_ ```console $ cat <<EOF Install Kubernetes apps from helm charts or YAML files using the "install" command. You can also find the post-install message for each app with the "info" command. Usage: arkade install [flags] arkade install [command] Aliases: install, i Examples: arkade install arkade install openfaas --gateways=2 arkade install inlets-operator --token-file $HOME/do-token EOF ``` 4\. Press `Enter` multiple times, until the output disappears from the current window. 5\. Enter tmux's copy mode with `Ctrl-B [` > Note: _first `Ctrl-B`, then `[`. Not simultaneously_ 6\. Scroll up with arrow keys or `PgUp` 7\. Copy the previously generated output. 8\. _(optional)_ Press `q` to exit tmux's copy mode. ![image](https://user-images.githubusercontent.com/3299086/106384071-8ec84d00-63c9-11eb-95fe-ba5337ed74e3.png) # Expected behavior The copied text contains line breaks at the end of each line. In this case, I'm expecting: ``` You can also find the post-install message for each app with the "info" command. Usage: arkade install [flags] arkade install [command] Aliases: install, i ``` # Actual behavior This is the raw pasted text. Notice the spaces before "Aliases" instead of the new line (I can replicate the issue with any text, not only that one): ``` You can also find the post-install message for each app with the "info" command. Usage: arkade install [flags] arkade install [command] Aliases: install, i ``` ℹ️ **Important note**: this happens only in tmux's copy mode. After pressing `q`, copying the same output will work as expected.
Author
Owner

@zadjii-msft commented on GitHub (Feb 1, 2021):

Wait hold up, isn't this #8532?

/cc @DHowett

@zadjii-msft commented on GitHub (Feb 1, 2021): Wait hold up, isn't this #8532? /cc @DHowett
Author
Owner

@antoineco commented on GitHub (Feb 1, 2021):

@zadjii-msft no, it happens with any Unix command, contrary to what I though. The example in #8532 was arguably a bad a example, so I opened a new issue with a better repro.

@antoineco commented on GitHub (Feb 1, 2021): @zadjii-msft no, it happens with any Unix command, contrary to what I though. The example in #8532 was arguably a bad a example, so I opened a new issue with a better repro.
Author
Owner

@DHowett commented on GitHub (Feb 1, 2021):

Here's the deal: If tmux is aware of the copy (it is handling selection and displaying the count/range of selected characters), that is completely outside of our control. We're forwarding mouse events off to tmux, and it is sending us back a base64-encoded version of what you selected. We turn that into UTF-8 and slap it directly onto your clipboard -- no further transformation is done.

If tmux is not aware of the copy (you're holding down shift while selecting, it is not displaying the top right indicator you pointed out, and the selection looks "non-native" (like a transparent overlay on top of your screen)), then it's our problem.

It's only arguably our problem, however. Terminal multiplexers own the entire screen, and they get the final say as to how lines are laid out. If they're laid out in such a way as to think we've wrapped (or not wrapped), that's on them. It's completely untenable in some situations, too, for terminal-bound copy (that is: tmux unaware) to operate correctly e.g. when there are tmux panes in view. Right? So... I dunno.

@DHowett commented on GitHub (Feb 1, 2021): Here's the deal: If tmux is aware of the copy (it is handling selection and displaying the count/range of selected characters), that is _completely_ outside of our control. We're forwarding mouse events off to tmux, and it is sending us back a base64-encoded version of what you selected. We turn that into UTF-8 and slap it directly onto your clipboard -- no further transformation is done. If tmux is _not_ aware of the copy (you're holding down shift while selecting, it is not displaying the top right indicator you pointed out, and the selection looks "non-native" (like a transparent overlay on top of your screen)), then it's our problem. It's only _arguably_ our problem, however. Terminal multiplexers own the entire screen, and they get the final say as to how lines are laid out. If they're laid out in such a way as to think we've wrapped (or not wrapped), that's on them. It's completely untenable in some situations, too, for terminal-bound copy (that is: tmux unaware) to operate correctly e.g. when there are tmux panes in view. Right? So... I dunno.
Author
Owner

@antoineco commented on GitHub (Feb 1, 2021):

Just to clarify, I have mouse support disabled in tmux. The count in the top right corner is shown because I entered copy mode with the key combination mentioned in the issue description.

In other words, tmux is not aware of the copy.

There is no pane involved here. I'm not expecting text to be copied properly when multiple panes are open, but in a fullscreen window this sounds like something any terminal should get right (at least none of the terminal emulators I've used on Windows and other platforms have this issue).

@antoineco commented on GitHub (Feb 1, 2021): Just to clarify, I have mouse support _disabled_ in tmux. The count in the top right corner is shown because I entered copy mode with the key combination mentioned in the issue description. In other words, tmux is not aware of the copy. There is no pane involved here. I'm not expecting text to be copied properly when multiple panes are open, but in a fullscreen window this sounds like something any terminal should get right (at least none of the terminal emulators I've used on Windows and other platforms have this issue).
Author
Owner

@DHowett commented on GitHub (Feb 1, 2021):

I believe tmux copy mode is intended to be combined with actually copying using tmux's copying bindings. Second case currently applies. I agree that it's annoying and I do want it fixed, but it's another one in the class of "sometimes terminal gets confused about which lines wrap" bugs. @zadjii-msft can likely find the parent duplicate.

@DHowett commented on GitHub (Feb 1, 2021): I believe tmux copy mode is intended to be combined with _actually copying using tmux's copying bindings_. Second case currently applies. I agree that it's annoying and I do want it fixed, but it's another one in the class of "sometimes terminal gets confused about which lines wrap" bugs. @zadjii-msft can likely find the parent duplicate.
Author
Owner

@antoineco commented on GitHub (Feb 1, 2021):

@DHowett copy mode is how you scroll in tmux. When you need to go back in history, you enter copy mode. If you have mouse support enabled this will happen when you actually scroll the mouse and you may not realize it, but it is still the same copy mode.

I would gladly use the tmux native copy if I could easily copy the contents of the buffer to the Windows clipboard, but in practice there is no good solution for that.

@antoineco commented on GitHub (Feb 1, 2021): @DHowett copy mode is how you scroll in tmux. When you need to go back in history, you enter copy mode. If you have mouse support enabled this will happen when you actually scroll the mouse and you may not realize it, but it is still the same copy mode. I would gladly use the tmux native copy if I could easily copy the contents of the buffer to the Windows clipboard, but in practice there is no good solution for that.
Author
Owner

@antoineco commented on GitHub (Feb 2, 2021):

Not a plug for another project but just to clarify the behaviour I see in other terminal emulators. Here with mintty/wsltty.

Reproduce the behaviour explained in the issue description (n.b. native copy, mouse support still disabled in tmux):

image

Raw paste:

You can also find the post-install message for each app with the "info"
command.

Usage:
  arkade install [flags]
  arkade install [command]

Aliases:
  install, i

Examples:
  arkade install
  arkade install openfaas  --gateways=2
  arkade install inlets-operator --token-file /home/acotten/do-token

It always works, no matter how I resize the terminal window (n.b. the actual window, not a tmux pane). In Windows Terminal, the line breaks seem to be sensitive to the current window size.

@antoineco commented on GitHub (Feb 2, 2021): Not a plug for another project but just to clarify the behaviour I see in other terminal emulators. Here with [mintty/wsltty](https://github.com/mintty/wsltty/). Reproduce the behaviour explained in the issue description (_n.b. native copy, mouse support still disabled in tmux_): ![image](https://user-images.githubusercontent.com/3299086/106620178-9aef0e80-6571-11eb-9cda-3f42d9015a2c.png) Raw paste: ``` You can also find the post-install message for each app with the "info" command. Usage: arkade install [flags] arkade install [command] Aliases: install, i Examples: arkade install arkade install openfaas --gateways=2 arkade install inlets-operator --token-file /home/acotten/do-token ``` It always works, no matter how I resize the terminal window (_n.b. the actual window, not a tmux pane_). In Windows Terminal, the line breaks seem to be sensitive to the current window size.
Author
Owner

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

This kinda seems like it's a dupe of #6901?

@zadjii-msft commented on GitHub (Nov 8, 2022): This kinda seems like it's a dupe of #6901?
Author
Owner

@thammegowda commented on GitHub (Dec 2, 2022):

I think I have the same problem: I copied some text from tmux copy/scroll mode (CTRL+B [) and pasted to Excel sheet .
My text which had many line breaks in terminal got pasted into a single row in Excel desktop app, thus ignoring line breaks after paste. Same thing with Sharepoint and Google sheets (Web apps).
When I exit CTRL+B [ mode and copy paste text bottom few lines (without scrolling up via CTRL+B [), the line breaks are preserved during the paste as expected.
I don't think this issue is dupe of #6901; the other issue seems to be about spurious additional line breaks than expected, where ass this issue is missing line breaks.

@thammegowda commented on GitHub (Dec 2, 2022): I think I have the same problem: I copied some text from tmux copy/scroll mode (`CTRL+B [`) and pasted to Excel sheet . My text which had many line breaks in terminal got pasted into a single row in Excel desktop app, thus ignoring line breaks after paste. Same thing with Sharepoint and Google sheets (Web apps). When I exit `CTRL+B [` mode and copy paste text bottom few lines (without scrolling up via CTRL+B [), the line breaks are preserved during the paste as expected. I don't think this issue is dupe of #6901; the other issue seems to be about spurious additional line breaks than expected, where ass this issue is missing line breaks.
Author
Owner

@crmky commented on GitHub (Feb 10, 2024):

I still see this issue in 1.19.240130002.

I have narrow down the issue to the TERM settings. If I set TERM to either xterm-256color or ms-terminal, this issue is gone. Otherwise if I set it to either screen-256color or tmux-256color, when copying multiple lines from vim, windows terminal will merge them into a single line.

I tried to compare infocmp output for those terminal types, but I can't find out which field caused that behavior. But at least you may workaround this issue by setting TERM variable.

@crmky commented on GitHub (Feb 10, 2024): I still see this issue in `1.19.240130002`. I have narrow down the issue to the `TERM` settings. If I set `TERM` to either `xterm-256color` or `ms-terminal`, this issue is gone. Otherwise if I set it to either `screen-256color` or `tmux-256color`, when copying multiple lines from vim, windows terminal will merge them into a single line. I tried to compare `infocmp` output for those terminal types, but I can't find out which field caused that behavior. But at least you may workaround this issue by setting `TERM` variable.
Author
Owner

@vadimkantorov commented on GitHub (May 12, 2025):

Same problem with TERM=screen :(

@vadimkantorov commented on GitHub (May 12, 2025): Same problem with `TERM=screen` :(
Author
Owner

@DHowett commented on GitHub (May 13, 2025):

This is very likely to be an incoming duplicate of #17225. There is a comment in the code exactly where I'd expect to find this bug referring to #15602, which is a duplicate of #17225 (higher number because it has more information.)

545eaf258d/src/terminal/adapter/adaptDispatch.cpp (L163-L168)

TL;DR: we should set WrapForced when we write the character in cell W+1, but we set it when we write cell W.

@DHowett commented on GitHub (May 13, 2025): This is very likely to be an incoming duplicate of #17225. There is a comment in the code exactly where I'd expect to find this bug referring to #15602, which is a duplicate of #17225 (higher number because it has more information.) https://github.com/microsoft/terminal/blob/545eaf258d8d7a66717ac2ac9b1a1e37b271ad29/src/terminal/adapter/adaptDispatch.cpp#L163-L168 TL;DR: we should set WrapForced when we write the character in cell W+1, but we set it when we write cell W.
Author
Owner

@DHowett commented on GitHub (May 13, 2025):

@lhecker in 17225, you enumerated a set of tests that failed because ConPTY's output changed. That was why we never removed the incorrect SetWrapForced on adaptDispatch.cpp:166.

Now that VtEngine is pushing up daisies, should we reevaluate removing this SetWrapForced? I think it will finally eliminate this class of issues.

@DHowett commented on GitHub (May 13, 2025): @lhecker in 17225, you enumerated a set of tests that failed because _ConPTY's output changed_. That was why we never removed the incorrect SetWrapForced on adaptDispatch.cpp:166. Now that VtEngine is pushing up daisies, should we reevaluate removing this SetWrapForced? I think it will finally eliminate this class of issues.
Author
Owner

@DHowett commented on GitHub (May 14, 2025):

Alright, tonight's canary build should have this fix. I would very much appreciate it if one of you fine folks could give it a shot. It should be out by 9PM pacific time.

@DHowett commented on GitHub (May 14, 2025): Alright, tonight's canary build should have this fix. I would very much appreciate it if one of you fine folks could give it a shot. It should be out by 9PM pacific time.
Author
Owner

@DHowett commented on GitHub (Jun 24, 2025):

Were any of you folks able to test this out in 1.24 Canary? If it's working well, I'd like to mark it for inclusion in the 1.23 (and maybe 1.22) updates coming out this week

@DHowett commented on GitHub (Jun 24, 2025): Were any of you folks able to test this out in 1.24 Canary? If it's working well, I'd like to mark it for inclusion in the 1.23 (and maybe 1.22) updates coming out this week
Author
Owner

@vadimkantorov commented on GitHub (Jun 25, 2025):

The "About" window in Terminal does not guide to switching the stock Windows terminal to the nightly version, so I've been to lazy to install the 1.24 as a sidekick :( so far my version is 1.22.11141.0 and it does not find any available updates after "checking for updates"

@vadimkantorov commented on GitHub (Jun 25, 2025): The "About" window in Terminal does not guide to switching the stock Windows terminal to the nightly version, so I've been to lazy to install the 1.24 as a sidekick :( so far my version is 1.22.11141.0 and it does not find any available updates after "checking for updates"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#12335