Keywords: Sublime Text | Multi-cursor Editing | Batch Selection | Keyboard Shortcuts | Code Refactoring
Abstract: This paper comprehensively examines the keyboard shortcuts for rapidly selecting all matching text instances in Sublime Text editor, with primary focus on the CMD+CTRL+G combination for macOS systems and comparative analysis of the Alt+F3 alternative for Windows/Linux platforms. Through practical code examples, it demonstrates application scenarios of multi-cursor editing technology, explains the underlying mechanisms of regex search and batch selection, and provides methods for customizing keyboard shortcuts to enhance developer productivity in text processing tasks.
Core Shortcut Operation Mechanism
In Sublime Text editor, rapidly selecting all matching text instances represents a crucial functionality for enhancing coding efficiency. When developers need to batch modify variable names, function calls, or specific strings in code, traditional manual find-and-replace approaches prove both time-consuming and error-prone. Sublime Text addresses this through intelligent multi-cursor editing technology that offers an elegant solution.
Standard Implementation on macOS
According to the best practice answer, on macOS operating systems, users can achieve this functionality through the CMD + CTRL + G key combination. This shortcut design reflects Sublime Text's deep understanding of developer workflows. When users select any text fragment and press these three keys, the editor immediately executes the following operation sequence:
- Analyzes the currently selected text content as the search pattern
- Searches the entire document for all instances matching this pattern
- Creates independent cursor positions for each matching occurrence
- Simultaneously selects all matched text regions
This process can be understood through the following pseudocode example illustrating its implementation logic:
def select_all_instances(selected_text, document_content):
matches = find_all_matches(selected_text, document_content)
if matches:
create_multiple_cursors_at(matches)
highlight_all_matched_regions()
return True
return False
Cross-Platform Alternative Comparison
For Windows and Linux users, the standard shortcut is Alt+F3. Although the key combinations differ, the core logic of functionality implementation remains consistent. These cross-platform variations primarily stem from operating system-level shortcut conventions rather than fundamental differences in feature implementation. Developers can customize shortcut mappings in the Preferences > Key Bindings configuration file according to their usage habits.
Practical Application Scenario Analysis
Consider the following JavaScript code refactoring scenario:
// Original code
function calculateTotal(price, quantity) {
let total = price * quantity;
console.log("Total calculated: " + total);
return total;
}
function calculateDiscount(total, rate) {
let discount = total * rate;
console.log("Discount calculated: " + discount);
return discount;
}
If needing to rename all calculate functions to compute, traditional methods would require individual find-and-replace operations. Using Sublime Text's select all instances feature, developers simply:
- Select any occurrence of the
calculateword - Press CMD+CTRL+G (macOS) or Alt+F3 (Windows/Linux)
- All
calculateinstances become simultaneously selected - Directly type
computeto complete batch renaming
Advanced Functionality Extension
Sublime Text's selection feature also supports regular expression patterns. When selecting text containing regex special characters, the editor automatically recognizes and enables regex matching mode. For example, selecting \d+ and using the shortcut will select all numerical sequences throughout the document.
This intelligent recognition mechanism implements through the following algorithm:
def detect_pattern_type(selected_text):
# Check for regular expression special characters
regex_chars = ['.', '*', '+', '?', '[', ']', '(', ')', '{', '}', '\\', '^', '$', '|']
for char in regex_chars:
if char in selected_text:
return 'regex'
return 'literal'
Performance Optimization Considerations
When processing large documents, Sublime Text employs incremental search and caching mechanisms to ensure responsive performance. The editor maintains document index structures, so when executing batch selection operations, it doesn't simply perform linear scanning but utilizes pre-built text indexes to rapidly locate all matching positions. This design enables selection of all instances to complete within milliseconds even in code files containing tens of thousands of lines.
Configuration and Customization
Users can customize shortcuts by editing Default (OSX).sublime-keymap or the corresponding platform key mapping files. For example, to bind the functionality to CMD+Shift+F:
[
{
"keys": ["super+shift+f"],
"command": "find_all_under",
"context": [
{ "key": "selection_empty", "operator": "equal", "operand": false }
]
}
]
This flexibility allows developers to optimize their editing environment according to personal work habits, further enhancing development efficiency.