VS Code Tips: Editing Tips

Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026

The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.


Removing Empty Lines

To remove empty lines from a file:

  1. Open Find and Replace (cmd-H)
  2. Enable regex mode (click the .* icon)
  3. Search for \n\n and replace with \n
  4. Run “Replace All”

You may need to run it multiple times until you get down to single empty lines.

Pro tip: Use \n\n+ to replace all consecutive empty lines at once without repeating the operation.

Search and Replace with Regular Expressions

VS Code supports powerful regex-based find and replace. Here’s a real-world example:

Example: Wrapping Image Paths with Special Characters

Suppose you need to update image links with spaces in their filenames:

![Alt text](Screen Shot 2021-10-16 at 09.45.47.png)

to:

![Alt text](<Screen Shot 2021-10-16 at 09.45.47.png>)

Use this regex to find images with spaces:

!\[(.+)\]\((.*\s+.*)\)

This creates two capturing groups:

  1. $1 - the alt text
  2. $2 - the filename

Then use this replacement:

![$1](<$2>)

For images without alt text, use:

!\[\]\((.*\s+.*)\)

With replacement:

![](<$1>)

Testing Regex

Use regex101.com to quickly test your regular expressions before using them in VS Code.

Lessons in this unit:

0: Introduction
1: Setup and Configuration Tips
2: Terminal Tips
3: ▶︎ Editing Tips
4: Prettier and Auto-Formatting
5: Language-Specific Settings
6: Emmet for Faster HTML/CSS
7: Debugging in VS Code
8: Fix node modules import errors in VS Code
9: Fixing TS issues in VS Code - Astro
10: regex select entire line starting with..