DEV Community

Akshay Joshi
Akshay Joshi

Posted on

VSCode Tip 2 : Multi-Cursor Editing

Multi-cursor editing allows you to make multiple changes at once, which can be a huge time-saver.

How to Use Multi-Cursor Editing:

  1. Add Cursors at Multiple Locations:

    • Windows/Linux: Press Ctrl + Alt and use the arrow keys to add a cursor above or below the current line.
    • Mac: Press Cmd + Option and use the arrow keys to add a cursor above or below the current line.
  2. Add Cursors with Mouse:

    • Anywhere: Hold Alt and click at the locations where you want to add cursors.
  3. Add Cursors to Next Occurrence:

    • Windows/Linux: Press Ctrl + D to add a cursor to the next occurrence of the selected text.
    • Mac: Press Cmd + D to add a cursor to the next occurrence of the selected text.
  4. Select All Occurrences:

    • Windows/Linux: Press Ctrl + Shift + L to select all occurrences of the current selection.
    • Mac: Press Cmd + Shift + L to select all occurrences of the current selection.

Example Usage:

  1. Changing Variable Names:
    If you need to change a variable name across multiple lines:

    • Select the variable name.
    • Press Ctrl + D or Cmd + D to add cursors to each occurrence.
    • Type the new name.
  2. Editing Multiple Lines:
    If you need to add the same text at the beginning or end of multiple lines:

    • Use Ctrl + Alt + Down Arrow or Cmd + Option + Down Arrow to create multiple cursors.
    • Type the text you want to add.

Multi-cursor editing is a powerful feature that can significantly speed up your coding workflow in VSCode.

Happy Coding!!!

Top comments (0)