Ora

How do you edit multiple lines in Sublime?

Published in Sublime Text Editing 4 mins read

Editing multiple lines in Sublime Text is a powerful feature that significantly boosts productivity, allowing you to make identical changes across several lines or instances of text simultaneously.

How to Edit Multiple Lines in Sublime Text

Sublime Text offers several intuitive methods for multi-line editing, catering to different scenarios, from simple column selection to advanced find-and-replace-like multi-selections. Mastering these techniques will streamline your coding and text manipulation tasks.

1. Multiple Selection (Column Editing)

This method is ideal when you need to edit text in a straight column or add/remove content at the same horizontal position across multiple lines.

  • Using Mouse Drag:
    • Windows/Linux: Hold Shift + Right Click and drag your mouse vertically to select a column of text or place multiple cursors.
    • macOS: Hold Option (or Alt) + Click and drag your mouse vertically. You can also use Ctrl + Shift + Click to place individual cursors.
  • From Selected Lines:
    • Select the lines you want to edit.
    • Press Ctrl + Shift + L (Windows/Linux) or Cmd + Shift + L (macOS). This will split your selection into multiple cursors at the end of each selected line, or at the start if nothing is selected.

2. Find and Replace Multi-Selection

This is arguably the most frequently used and versatile method, particularly for editing non-contiguous instances of text.

  • Select Next Instance:
    • Select the first instance of the text you want to edit.
    • Press Ctrl + D (Windows/Linux) or Cmd + D (macOS). This action selects the next occurrence of the currently selected text. You can repeatedly press this shortcut to select more instances one by one. This is a very common method for multi-line editing.
    • If you select an instance, then press Cmd+D to select the next instance of selected text.
  • Skip an Instance:
    • While using Ctrl + D or Cmd + D to select instances, if you encounter an instance you wish to skip, press Ctrl + K, Ctrl + D (Windows/Linux) or Cmd + K, Cmd + D (macOS). This deselects the current instance and moves the focus to the next, allowing you to pick and choose your edits precisely.
  • Select All Instances:
    • Select the text you want to modify across the entire document.
    • Press Alt + F3 (Windows/Linux) or Ctrl + Cmd + G (macOS). This will instantly select all occurrences of the selected text within the file, placing a cursor at the end of each, ready for simultaneous editing.
  • Manual Cursor Placement:
    • Hold Ctrl (Windows/Linux) or Cmd (macOS) and click at any desired location to place multiple, independent cursors. This gives you absolute control over cursor placement.

Key Shortcuts for Multi-Line Editing

Here's a quick reference table for the essential multi-line editing shortcuts in Sublime Text:

Action Windows/Linux Shortcut macOS Shortcut Description
Column Selection Shift + Right Click drag Option + Click drag Selects a vertical column of text or places cursors.
Split Selection to Lines Ctrl + Shift + L Cmd + Shift + L Places cursors at the end of each selected line.
Select Next Instance Ctrl + D Cmd + D Selects the next occurrence of the current selection.
Skip Instance Ctrl + K, Ctrl + D Cmd + K, Cmd + D Skips the current instance and selects the next.
Select All Instances Alt + F3 Ctrl + Cmd + G Selects all occurrences of the current selection in the file.
Manual Cursor Placement Ctrl + Click Cmd + Click Places an independent cursor at the clicked location.

For more detailed information, you can always refer to the official Sublime Text documentation.

Practical Use Cases and Tips

  • Renaming Variables/Functions: Quickly update all instances of a variable name throughout a scope.
  • Adding/Removing Prefixes/Suffixes: Append or prepend text to multiple lines, like adding a bullet point to a list or a file extension.
  • Editing Lists or CSV Data: Modify specific columns or elements across many rows.
  • Refactoring Code: Efficiently change argument names, function calls, or HTML tags.
  • Combine with other commands: Once you have multiple cursors, you can use other standard editing commands (e.g., Delete, Backspace, Ctrl+Shift+K for deleting entire lines, Ctrl+Shift+V to paste each line of clipboard as a new selection) for even more complex manipulations.

By leveraging these multi-line editing features, you can significantly reduce repetitive tasks and enhance your editing workflow in Sublime Text.