Copy on Select ignore trailing whitespaces #9553

Open
opened 2026-01-31 01:57:38 +00:00 by claunia · 5 comments
Owner

Originally created by @davy-tw on GitHub (Jul 11, 2020).

Description of the new feature/enhancement

While copying on select, auto ignore trailing whitespaces on each line.

Why?

In my .vimrc, I draw 80 column and 120 column line via background color like this:

image

function! SetColumnWarnOnResized()
  highlight Normal ctermbg=NONE
  if &columns > 120
    let &colorcolumn="81,".join(range(120, &columns), ",") " Set the column warns on 80 and 120+
  else
    let &colorcolumn="81" " Set the column warns on 80
  endif
endfunction
au VimResized * call SetColumnWarnOnResized()
call SetColumnWarnOnResized()     

When I select and copy these words in the screenshot above, Windows Terminal will fill my clipboard with many whitespaces like this (notice that wired whitespaces):

Some texts here...
And here...                                                                                                                                                         Notice the 80 col line in my vim --------------------------------------------->
And the 120 col line ================================================================================================>       

And this only happend sometimes (not always), I don't know if this is a bug?

Related issues

This issues may relatives to these issues:

Originally created by @davy-tw on GitHub (Jul 11, 2020). # Description of the new feature/enhancement While copying on select, auto ignore trailing whitespaces on each line. # Why? In my `.vimrc`, I draw 80 column and 120 column line via background color like this: ![image](https://user-images.githubusercontent.com/841969/87218091-388ab280-c382-11ea-8df3-8b37e0ff85d5.png) ```vim function! SetColumnWarnOnResized() highlight Normal ctermbg=NONE if &columns > 120 let &colorcolumn="81,".join(range(120, &columns), ",") " Set the column warns on 80 and 120+ else let &colorcolumn="81" " Set the column warns on 80 endif endfunction au VimResized * call SetColumnWarnOnResized() call SetColumnWarnOnResized() ``` When I select and copy these words in the screenshot above, Windows Terminal will fill my clipboard with many whitespaces like this (notice that wired whitespaces): ``` Some texts here... And here... Notice the 80 col line in my vim ---------------------------------------------> And the 120 col line ================================================================================================> ``` And this only happend sometimes (not always), I don't know if this is a bug? # Related issues This issues may relatives to these issues: * #2944 * #3088
claunia added the Issue-BugProduct-TerminalPriority-2Area-TerminalControl labels 2026-01-31 01:57:38 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Jul 16, 2020):

Huh. The nearly-exact wrapping there is really curious.

@zadjii-msft commented on GitHub (Jul 16, 2020): _Huh_. The nearly-exact wrapping there is really curious.
Author
Owner

@DHowett commented on GitHub (Jul 16, 2020):

This could be related to vim printing the entire row of text when it wants to apply a style to the 81st+ columns. We can't meaningfully know the difference between it wanting text over there and it wanting spaces over there. Hmm.

@DHowett commented on GitHub (Jul 16, 2020): This could be related to vim printing the entire row of text when it wants to apply a style to the 81st+ columns. We can't meaningfully know the difference between it wanting text over there and it wanting spaces over there. Hmm.
Author
Owner

@davy-tw commented on GitHub (Jul 18, 2020):

Hummm... So the workaround is not to print background on the last column.

But other terminals like gnome terminal (on Linux) and PuTTY (on Windows) can handle this well without trailing whitespaces, is there any technological issue?

@davy-tw commented on GitHub (Jul 18, 2020): Hummm... So the workaround is not to print background on the last column. But other terminals like gnome terminal (on Linux) and PuTTY (on Windows) can handle this well without trailing whitespaces, is there any technological issue?
Author
Owner

@alfredneu commented on GitHub (May 26, 2023):

Hi, the issue is still present and very annoying. Any chance for a fix? As david50407 said, other terminal emulators handle this fine, perhaps you could have a look how they do it.

@alfredneu commented on GitHub (May 26, 2023): Hi, the issue is still present and very annoying. Any chance for a fix? As david50407 said, other terminal emulators handle this fine, perhaps you could have a look how they do it.
Author
Owner

@smprather commented on GitHub (Mar 15, 2025):

I'm here because I'm still getting a variety of "that ain't right" when copy/pasting. Sometimes in nvim, sometimes just in bash, sometimes I'll get trailing whitespace on some lines and newline chars on other lines. And fixing up the trailing whitespace / no-newline mayhem is usually pretty painful.

Windows Terminal Preview
Version: 1.23.10353.0

@smprather commented on GitHub (Mar 15, 2025): I'm here because I'm still getting a variety of "that ain't right" when copy/pasting. Sometimes in nvim, sometimes just in bash, sometimes I'll get trailing whitespace on some lines and newline chars on other lines. And fixing up the trailing whitespace / no-newline mayhem is usually pretty painful. Windows Terminal Preview Version: 1.23.10353.0
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#9553