Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find \n and replace with \r\n in VS Code

I have a legacy system that only accepts Windows \r\n and I want to edit a file in VS Code that has just \n to have \r\n.

I'm trying to use a Regex replace:

regex replace in VS Code

But this puts literal \r in instead of the whitespace char.

I've tried putting a newline in the replacement using SHIFT+ENTER:

SHIFT+ENTER replace in VS Code

But this just puts in \n.

How do I change the line feed chars used and save the file in VS Code?

like image 696
Keith Avatar asked Feb 25 '26 04:02

Keith


1 Answers

There's the text "LF" in the bottom bar on the right, click on it and select "CRLF". Or press Ctrl+Shift+P and enter Change End of Line Sequence.

No idea why your approach doesn't work. Nor does \x0D or \15 get recognized. I'd call it a bug.


For multiple files, on Linux, I'd do it outside of the editor, e.g., with

find somedir -name '*.someext' -exec perl -pi -e 's/\n/\r\n/' {} +
like image 135
maaartinus Avatar answered Feb 27 '26 03:02

maaartinus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!