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
- Set the cursor in the first line you want to edit.
- Generate multiple cursors:
- On Windows, use
Ctrl+Alt+Down
orCtrl+Alt+Up
to insert more cursors on consecutive lines. UseAlt+Click
to add cursors to separate lines, not necessarily consecutive. - On Linux, use
Shift+Alt+Down
orShift+Alt+Up
to insert more cursors on consecutive lines. UseAlt+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.
- Make your edits!
In my case, I wanted to add bold Markdown to my words. So I took the following steps:
- Start at the beginning of the word.
- Add the
**
to start the bold. - Use
Ctrl + right-arrow
to move to the end of the word. Notice that it moved the cursor to the end of each word. - 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: