Using WSL2/WSLg and Ubuntu 22.04 LTS under it, with gVim running and has a Linux file opened (i.e. with LF endings only), when I paste text from Windows into gVim, all the lines pasted have the CR/^M characters pasted with them. For example:

This line is original from the Linux file.
This one too.
This line was pasted from Window's clipboard^M   <<< Lines pasted
and this one too.^M                              <<< from Windows
Now another original line from the Linux file.

How can I instruct gVim to eat up the carriage returns while pasting if the fileformat is unix?

I search the web to novail. Not even the GPT AIs of the day could provide me some help.

1 Answer 1


I don't know about fixing the paste automatically, but the edit is straightforward:


or the shorthand :'[,']s/\r$. Bind to a mapping, command, or even autocommand (on the condition that &l:fileformat='unix').

  • Yes, thank you for the workaround, but I already had one. I am really seeking a solution to solve directly this pasting problem. Sep 23, 2023 at 12:50
  • I see no real solution. gVim has no way to know if the clipboard has been filled in WSL and no translation should be made or if it has been filled in Windows and some translation should occur. Feb 20 at 6:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.