WSL - Trailing whitespaces being added to Bash code pasted into CMD WSL TTY per window size
As you stated, the issue arises from pasting text in a narrow window with Unix line-endings (LF).
Consider using the following AutoHotkey script to "type out" the clipboard text, letting Windows handle the newline characters.
SendMode Input ; Recommended for superior speed and reliability.
; Upon pressing Ctrl+Alt+v
^!v::
; SendRaw "types" the contents of the variable. When it encounters either
; Cr (`r) or Lf (`n), it sends an "Enter", thus CrLf sends Enter twice.
; Replace any CrLf with Lf (ironic, I know), leaving the clipboard as is
newClip := StrReplace(clipboard,"`r`n","`n")
SendRaw %newClip%
return
As suggested to me by Benno Schulenberg of the Nano development team, adding the following code in the end of /etc/nanorc solved this problem:
bind ^J enter main
On the one hand, this will disable formation of Trailing whitespaces, and on the other hand, will add Line Feeds (LF chars) to the data copied from Windows, so it won't appear in one long row.
Read here for more data.