โ† Back to DevBytes

Sublime Text Multi-Cursor Editing: Complete Guide

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.

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.

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.

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.

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:

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.

๐Ÿ›  Tools from DevBytes

Inventory Tracker Pro โ€” Excel inventory system, low-stock alerts ยท $19
AI Dev Kit for Mac โ€” local AI dev environment templates ยท $9.99
KeyMapper for Mac โ€” custom keyboard shortcut toolkit ยท $7.99

โ† Back to all articles