wslg icon indicating copy to clipboard operation
wslg copied to clipboard

Windows line endings (^M) are added when copying from Windows and pasting into Linux apps

Open nickjj opened this issue 8 months ago • 6 comments

Windows build number:

10.0.19045.0

Your Distribution version:

Arch Linux

Your WSL versions:

WSL version: 2.4.13.0
Kernel version: 5.15.167.4-1
WSLg version: 1.0.65
MSRDC version: 1.2.5716
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26100.1-240331-1435.ge-release
Windows version: 10.0.19045.5737

Steps to reproduce:

  1. Open Neovim
  2. Copy multiple lines of text from Windows
  3. Paste into Neovim using p when in normal mode
  4. Notice ^M being displayed at the end of each line that has a line break

Image

Here's multiple lines of text to use as an example:

Hello world
Here's a few lines of text
Yep, this is 3 lines

WSL logs:

No response

WSL dumps:

No response

Expected behavior:

The lines are pasted without Windows line endings.

Actual behavior:

The lines are pasted with Windows line endings.

Technically you can paste with CTRL+SHIFT+v using the Microsoft Terminal and it seems to strip or convert the line endings but in my opinion this should be the default behavior of the clipboard manager.

I used VcXsrv with WSL for around 8 years which had clipboard sharing and it handled this automatically. I never saw a Windows line ending when pasting into Vim, Neovim or any other Linux app that was able to read the system clipboard.

nickjj avatar Apr 21 '25 12:04 nickjj

reporting that it happens to me too

barbro avatar Jun 07 '25 19:06 barbro

I'm also experiencing this so I setup a workaround

B1LLP4RK avatar Jun 17 '25 05:06 B1LLP4RK

Perhaps Neovim can use wl-clipboard directly.

Dou-Meishi avatar Oct 14 '25 10:10 Dou-Meishi

Perhaps Neovim can use wl-clipboard directly.

I am already using wl-clipboard which is a Wayland clipboard manager on Linux, although the problem happens with xclip too.

I think you might have meant using clip.exe in which case it would likely work but that means modifying an application to work specifically with WSL 2 when it works with native Linux. That's a bad path to go down IMO if you need to modify apps to work with WSL 2. Plus it was solved 8 years ago with VcXsrv, so it can be handled internally with the tool that's responsible for bridging between WSL 2 and Windows.

nickjj avatar Oct 14 '25 11:10 nickjj

Ideally we wouldn't need to adjust every Linux application for WSL workarounds.

Other clipboard sharing tools mentioned earlier handled this internally.

On Sat, Nov 1, 2025, 10:46 PM Muhammed Murad Çiftçi < @.***> wrote:

muradcift left a comment (microsoft/wslg#1326) https://github.com/microsoft/wslg/issues/1326#issuecomment-3476741482

The issue is caused by the carriage return. While Linux uses \n for line endings, Windows uses \r\n. If you add these commands to your init.lua file, it will be fixed.

vim.opt.fileformat = "unix" vim.opt.fileformats = "unix,dos"

— Reply to this email directly, view it on GitHub https://github.com/microsoft/wslg/issues/1326#issuecomment-3476741482, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGGRI3IGLNNUV2ITHG4FG332UE2DAVCNFSM6AAAAAB3RGBTYCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTINZWG42DCNBYGI . You are receiving this because you authored the thread.Message ID: @.***>

nickjj avatar Nov 02 '25 02:11 nickjj

" WSL paste fix autocmd BufReadPost * call s:lastpos() function! WslCleanup() silent! exe "'[,']s/\r$//g" endfunction nnoremap p p:call WslCleanup() nnoremap P P:call WslCleanup()

this is the vimscript macro i use right know to hack my way around this problem

barbro avatar Nov 14 '25 01:11 barbro