Introduction to Multi-Cursor Editing
Sublime Text is renowned for its speed and efficiency, and one of its most powerful features is multi-cursor editing. Multi-cursor editing allows developers to place multiple cursors in a document simultaneously, enabling them to type, delete, or edit text in several different locations at the exact same time.
Why does this matter? In traditional text editing, making repetitive changes across a file requires tedious find-and-replace operations or manually clicking through each instance. Multi-cursor editing eliminates this bottleneck. Whether you are renaming a variable that appears a dozen times in a function, formatting a list of data, or wrapping multiple HTML tags, multi-cursor editing drastically reduces keystrokes, minimizes human error, and keeps you in a state of flow.
How to Use Multi-Cursor Editing
Sublime Text provides several ways to invoke multi-cursor mode, depending on your specific editing needs. Below are the most common methods. Note that keyboard shortcuts are listed as Cmd for macOS and Ctrl for Windows/Linux.
Adding Cursors Manually
The simplest way to add a cursor is to click directly where you want it while holding down the modifier key.
- Mac:
Cmd + Click - Windows/Linux:
Ctrl + Click
You can add as many cursors as you need. Once placed, any keystroke will be applied to all cursor locations simultaneously. To exit multi-cursor mode, simply press the Esc key.
Selecting Multiple Instances of a Word
If you need to edit a specific word or variable that appears multiple times, you can select them sequentially or all at once.
- Select Next: Highlight a word and press
Cmd + D(Mac) orCtrl + D(Windows/Linux). This selects the next occurrence of the word and adds a cursor. - Skip Next: If you want to skip an occurrence while using
Cmd/Ctrl + D, pressCmd + K, Cmd + D(Mac) orCtrl + K, Ctrl + D(Windows/Linux). - Select All: To select all occurrences of the highlighted word in the file, press
Cmd + Ctrl + G(Mac) orAlt + F3(Windows/Linux).
Splitting Selection into Lines
When you have a block of text selected across multiple lines and you want to edit the end or beginning of each line, you can split the selection.
- Mac:
Cmd + Shift + L - Windows/Linux:
Ctrl + Shift + L
After splitting, you can press the arrow keys to move all cursors to the beginning or end of the lines simultaneously.
Column Selection
For selecting a rectangular block of text, Sublime Text supports column selection.
- Mouse: Middle-click and drag, or hold
Shiftand right-click and drag. - Keyboard: Hold
Ctrl + Alt(Windows/Linux) orCmd + Option(Mac) and use the Up/Down arrow keys.
Practical Examples
To understand the true power of multi-cursor editing, let's look at a couple of practical scenarios.
Example 1: Refactoring Variable Names
Imagine you have the following JavaScript code and you want to change the prefix user_ to profile_ for all variables in this specific block, but not elsewhere in the file.
const user_id = 1;
const user_name = "Alice";
const user_email = "alice@example.com";
const user_role = "admin";
Instead of using a global Find and Replace, you can highlight user_ on the first line. Press Cmd/Ctrl + D three times to select the remaining instances. Then, simply type profile_. All four lines will update instantly:
const profile_id = 1;
const profile_name = "Alice";
const profile_email = "alice@example.com";
const profile_role = "admin";
Example 2: Formatting CSV to JSON
Suppose you have a raw list of comma-separated values and you need to convert them into a JSON array format.
apple, 1.99
banana, 0.59
cherry, 2.99
date, 4.50
You can select all four lines, then press Cmd/Ctrl + Shift + L to split the selection into lines. Press the End key to move all cursors to the end of their respective lines, and type a comma. Next, press Home to move all cursors to the beginning of the lines, and type {"name": ". Finally, use the arrow keys to navigate to the comma separating the fruit and the price, and adjust the syntax to close the string and add the price key. The result is formatted simultaneously:
{"name": "apple", "price": 1.99},
{"name": "banana", "price": 0.59},
{"name": "cherry", "price": 2.99},
{"name": "date", "price": 4.50},
Best Practices for Multi-Cursor Editing
To get the most out of multi-cursor editing, keep the following best practices in mind:
- Combine with Find and Replace: You can use the Find panel (
Cmd/Ctrl + F) or Find in Files (Cmd/Ctrl + Shift + F) with the "Find All" button to place cursors on specific search terms or regular expression matches before editing. - Use the Escape Key: If you accidentally add too many cursors or make a mistake,
Escis your best friend. It will collapse all cursors into a single cursor, allowing you to start over. - Undo History is Unified: Remember that
Cmd/Ctrl + Zwill undo the last action across all cursors. If you make a mistake across 10 cursors, one undo will revert the change for all 10. - Watch Your Line Endings: When using multi-cursor across lines of varying lengths, be cautious when using the Left/Right arrow keys. It is usually safer to use
HomeandEndto align cursors to the start or end of lines.
Conclusion
Multi-cursor editing is a transformative feature that turns repetitive text manipulation into a fast, seamless process. By mastering manual cursor placement, sequential selection, and line splitting, you can dramatically reduce the time spent on refactoring and formatting tasks. Like any advanced tool, it requires a bit of practice to build muscle memory, but once you integrate these shortcuts into your daily workflow, you will find it difficult to return to a standard single-cursor editor. Start practicing these techniques in Sublime Text today, and watch your coding efficiency soar.