3

I can able to do the find and replace for a single file by putting ^\s*$\n and replacing it with nothing. But Visual Studio Code is not allowing the same for multiple files.

Literal '\n' is not allowed enter image description here

How can I do this in Visual Studio Code or Any other faster solution? BTW I am doing it on node.js project.

Edit VS Code not allowing \n for multi file find and replace enter image description here

9
  • In the "files to include/exclude" field put in *.* or the files you want to include. Commented Apr 14, 2018 at 7:11
  • No, by default it include all files. Commented Apr 14, 2018 at 7:17
  • I am able to perform non '\n' replace on multiple files. Commented Apr 14, 2018 at 7:18
  • Try using \\n instead of \n... see: stackoverflow.com/a/43483515/499581 Commented Apr 14, 2018 at 7:27
  • ^\s*$\\n not working. It is considering it as slash + n string Commented Apr 14, 2018 at 7:28

1 Answer 1

2

You can try this with [\n\r] instead of \n

^\s*$[\n\r]

find with regex in vscode

Btw, it seems ^\s*$ finds greatly more empty lines than above.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks a lot :-) this worked. I hope VS Code will add such option before we have to come up with complicated solution ;)
Sorry,It looks like your syntax was able to find all those lines but when I am replacing it, it doesn't work. Did you tried removing the empty lines with same syntax in multiple files?
It looks like a bug in VS Code. Can you please check on your side. Will be great help :-) for future projects as well.
Sorry to say that find & replace in files in vscode seems not working properly in some regex pattern at this time and works some differently from find for a file. I recommend using other text editors(e.g. notepad++, etc) for finding & replacing in multiple files with regex

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.