0

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

0

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

:'[,']substitute/\r$//

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

1
  • 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 at 12:50

Your Answer

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

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