Edit Multiple Lines Simultaneously with Visual Studio Code

June 13, 2024#Tools
Article
Author image.

Sarah Dutkiewicz, Senior Trainer

Have you ever had a moment where you need to make the same edits to multiple lines in a file? Maybe you have a list that needs bullets added at the beginning and don’t want to add the bullets individually? I recently had a case where I needed to bold the concepts appearing in my Clean Architecture course and didn’t want to deal with each change individually. I used to use Notepad++ long ago to do multi-line editing, and I was curious whether I could do it in Visual Studio Code. It turns out - I can!

Steps for Multi-Line Editing in Visual Studio Code

  1. Set the cursor in the first line you want to edit.
  2. Generate multiple cursors:
  • On Windows, use Ctrl+Alt+Down or Ctrl+Alt+Up to insert more cursors on consecutive lines. Use Alt+Click to add cursors to separate lines, not necessarily consecutive.
  • On Linux, use Shift+Alt+Down or Shift+Alt+Up to insert more cursors on consecutive lines. Use Alt+Click to add cursors to separate lines, not necessarily consecutive.
  • On Mac, use ⌥+⌘+Down or ⌥+⌘+Up to insert more cursors on consecutive lines. Use ⌥+Click to add cursors to separate lines, not necessarily consecutive.
  1. Make your edits!

In my case, I wanted to add bold Markdown to my words. So I took the following steps:

  1. Start at the beginning of the word.
  2. Add the ** to start the bold.
  3. Use Ctrl + right-arrow to move to the end of the word. Notice that it moved the cursor to the end of each word.
  4. Add the ** to end the bold.

You can see this tip in action here:

Resources

These are some of the resources I use when working with edits and keyboard shortcuts in Visual Studio Code:


Copyright © 2024 NimblePros - All Rights Reserved