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

Viewed 7683

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?

3 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/' {} +

Just press Ctrl+H and select regex replace. Then start input:

Find what: ^\n

Replace with: \r\n

Related