Quick Tip: VSCode - Find and Replace with New Line

I made the switch to VSCode from Sublime Text a couple months ago, and there are quite a few subtle (and not-so-subtle) differences between the workflow. The first major difference I found was finding and replacing code that spanned across multiple lines. You simply can't do it feasibly in VSCode.

In Sublime (and Atom I believe), you can grab multiple lines of code and find and replace the entire code snippet with something else (like an entire other code snippet). It's totally possible in VSCode, don't get me wrong. But it requires you to manually RegEx the snippet each time.

It's a feature that's been requested since Nov 18, 2016. And there are plugins available, but they're not as elegant as just using the Find and Replace dialog.

The "Solution"

Switch your Find and Replace over to RegEx mode. Add \n or \t wherever you want a line break. It's a little tricky figuring out where it is sometimes, especially when applying it to snippets with tabbed indents.

You can also use *. continue the search across the line so it grabs everything.

Example

'something
like this'
'something\n like this'
-with regex enabled

You get the idea

It's really a shame that VSCode hasn't implemented this kind of feature. I don't mind flexing the RegEx muscles every now and then, but when it inhibits my workflow -- and I know a competitor easily accomplishes it -- it's unacceptable.

I hope this helps you with this simple problem I had switching over.

Stay regular,
Oscar


Keep Reading:

Oscar

Oscar is an artist and engineer who's been creating cannabis brands and media experiences for over 10 years, and developing full-stack applications for over 15 years.