Select and copy TAB characters without expanding to spaces #10863

Open
opened 2026-01-31 02:32:17 +00:00 by claunia · 10 comments
Owner

Originally created by @KalleOlaviNiemitalo on GitHub (Oct 2, 2020).

Description of the new feature/enhancement

After outputting a text file to the terminal, I want to copy part of it to the clipboard without expanding TAB characters to spaces. So that I can then paste it to a different file in which TAB characters are required.

Proposed technical implementation details (optional)

Remember which character cells were output as spaces and which ones were skipped over by TAB characters. When selecting text with the mouse, select entire TAB characters instead of individual character cells. Copy the TAB characters to the clipboard.

The macOS Terminal app has this feature. It does not preserve TAB characters in the following situations:

  • If outputting the TAB character moves the cursor over character cells of which at least one contains a different character already.
  • If the TAB character has already been output and a different character is then output to any of the character cells spanned by the TAB character.

I did not test whether the macOS Terminal app preserves TAB characters if they are moved using SCROLL LEFT, SCROLL RIGHT, or INSERT CHARACTER control functions, or if tabulation stops are changed. I think it would be OK to expand TAB characters to spaces in those situations.

Related:

Originally created by @KalleOlaviNiemitalo on GitHub (Oct 2, 2020). # Description of the new feature/enhancement After outputting a text file to the terminal, I want to copy part of it to the clipboard without expanding TAB characters to spaces. So that I can then paste it to a different file in which TAB characters are required. # Proposed technical implementation details (optional) Remember which character cells were output as spaces and which ones were skipped over by TAB characters. When selecting text with the mouse, select entire TAB characters instead of individual character cells. Copy the TAB characters to the clipboard. The macOS Terminal app has this feature. It does not preserve TAB characters in the following situations: * If outputting the TAB character moves the cursor over character cells of which at least one contains a different character already. * If the TAB character has already been output and a different character is then output to any of the character cells spanned by the TAB character. I did not test whether the macOS Terminal app preserves TAB characters if they are moved using SCROLL LEFT, SCROLL RIGHT, or INSERT CHARACTER control functions, or if tabulation stops are changed. I think it would be OK to expand TAB characters to spaces in those situations. Related: * <https://github.com/microsoft/terminal/issues/2656>, in which TAB characters were involved, but the problem was loss of newlines. * <https://github.com/microsoft/terminal/issues/32#issuecomment-334814519>, keeping track of whether empty character cells were written as spaces.
claunia added the Issue-FeatureProduct-ConhostArea-Output labels 2026-01-31 02:32:17 +00:00
Author
Owner

@DHowett commented on GitHub (Oct 2, 2020):

Yeah, I think this is totally worthwhile!

It's also going to be hard. Our buffer needs a deep rethink on how it stores a great number of things. 😄

@DHowett commented on GitHub (Oct 2, 2020): Yeah, I think this is totally worthwhile! It's also going to be hard. Our buffer needs a deep rethink on how it stores a great number of things. :smile:
Author
Owner

@Diego-TorresDev commented on GitHub (Oct 2, 2020):

Ah ok

@Diego-TorresDev commented on GitHub (Oct 2, 2020): Ah ok
Author
Owner

@KalleOlaviNiemitalo commented on GitHub (Apr 24, 2021):

If the TAB characters are part of a rectangular selection, and whitespace trimming is enabled (https://github.com/microsoft/terminal/issues/9706), I think they should be trimmed just like space characters.

https://github.com/microsoft/terminal/blob/2219014385c9b2b351bd0148b2aae385ce6427a1/src/buffer/out/textBuffer.cpp#L1678-L1679

@KalleOlaviNiemitalo commented on GitHub (Apr 24, 2021): If the TAB characters are part of a rectangular selection, and whitespace trimming is enabled (<https://github.com/microsoft/terminal/issues/9706>), I think they should be trimmed just like space characters. <https://github.com/microsoft/terminal/blob/2219014385c9b2b351bd0148b2aae385ce6427a1/src/buffer/out/textBuffer.cpp#L1678-L1679>
Author
Owner

@Musketeer-D commented on GitHub (Jul 5, 2021):

As a bioinformatics researcher, can select and copy TAB characters without expanding to spaces is the only reason that keep me using xshell while not win terminal. Please give this feature to your great terminal.
Thank you for your time !
I wish you all the best !

@Musketeer-D commented on GitHub (Jul 5, 2021): As a bioinformatics researcher, can select and copy TAB characters without expanding to spaces is the only reason that keep me using xshell while not win terminal. Please give this feature to your great terminal. Thank you for your time ! I wish you all the best !
Author
Owner

@Suleman-Elahi commented on GitHub (Jan 4, 2023):

Any update on this?

@Suleman-Elahi commented on GitHub (Jan 4, 2023): Any update on this?
Author
Owner

@zadjii-msft commented on GitHub (Jan 4, 2023):

Nope. We'll make sure to update this thread when there is. In the meantime, might I recommend the Subscribe button?
image
That way you'll be notified of any updates to this thread, without needlessly pinging everyone on this thread ☺️

@zadjii-msft commented on GitHub (Jan 4, 2023): Nope. We'll make sure to update this thread when there is. In the meantime, might I recommend the Subscribe button? ![image](https://user-images.githubusercontent.com/18356694/91237459-5cbb0c80-e700-11ea-9347-b9b1ec2813b1.png) That way you'll be notified of any updates to this thread, without needlessly pinging everyone on this thread ☺️
Author
Owner

@xdml commented on GitHub (May 19, 2023):

As a workaround I started to use for Ubuntu staff xfce4-terminal. This terminal preserve tab character in both ways.

@xdml commented on GitHub (May 19, 2023): As a workaround I started to use for Ubuntu staff `xfce4-terminal`. This terminal preserve tab character in both ways.
Author
Owner

@computator commented on GitHub (Jul 23, 2024):

Just wanted to note that Gnome Terminal which is the default terminal in Ubuntu also renders tabs as tabs. I am used to being able to copy git diffs, source code, and similar text from the terminal without breaking the formatting, but using the windows terminal this is not possible and I have to redirect the output to a file instead.

@computator commented on GitHub (Jul 23, 2024): Just wanted to note that Gnome Terminal which is the default terminal in Ubuntu also renders tabs as tabs. I am used to being able to copy git diffs, source code, and similar text from the terminal without breaking the formatting, but using the windows terminal this is not possible and I have to redirect the output to a file instead.
Author
Owner

@aa956 commented on GitHub (Jan 29, 2025):

Issue still relevant, especially as Legacy Console is (almost?) removed from Windows 11 24H2:

Manually running conhost.exe still works on Windows 11 24H2 but who knows for how long.

Are there any workarounds?

Image

Edit: thanks for the explanation, I should've tried copying from that window too, just immediately after seeing the old style console window thought that it was separate from the Windows Terminal.

@aa956 commented on GitHub (Jan 29, 2025): Issue still relevant, especially as Legacy Console is (almost?) removed from Windows 11 24H2: Manually running `conhost.exe` still works on Windows 11 24H2 ~~but who knows for how long~~. Are there any workarounds? ![Image](https://github.com/user-attachments/assets/9a5a1178-b0fc-4f55-b575-2687fb4b6cc1) Edit: thanks for the [explanation](https://github.com/microsoft/terminal/issues/7810#issuecomment-2622268329), I should've tried copying from that window too, just immediately after seeing the old style console window thought that it was separate from the Windows Terminal.
Author
Owner

@DHowett commented on GitHub (Jan 29, 2025):

We are not removing conhost from Windows.

The component we are removing from Windows is the old Windows 8 console. That one doesn't even support resizing, or most fonts.

You are not going to lose the ability to use the Windows Console.

FWIW: the console and the terminal use the same implementation for text storage, and conhost doesn't store tab characters either.

@DHowett commented on GitHub (Jan 29, 2025): We are not removing conhost from Windows. The component we are removing from Windows is the _old Windows 8 console._ That one doesn't even support resizing, or most fonts. You are not going to lose the ability to use the Windows Console. FWIW: the console and the terminal use the same implementation for text storage, and conhost doesn't store tab characters either.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#10863