Chameleon Selection
Chameleon Selection is a powerful Visual Studio Code extension designed to supercharge how you select multiple lines of text. By introducing a Domain-Specific Language (DSL) for text selection, it allows developers to quickly combine mathematical ranges, text filters, and sequence modifiers to perform complex line selections in record time.
✨ Features
- Domain-Specific Language (DSL): A rich, intuitive syntax combining mathematical intervals, CSS-like selectors, and regular expressions.
- Live Preview: See the lines that match your query highlighted in real-time as you type.
- Interactive Commands: Filter existing selections, add to them, or remove from them interactively.
- Real-time Validation: Get instant feedback if your DSL syntax is incomplete or invalid.
🚀 Getting Started
All Chameleon Selection commands are available through the VSCode Command Palette (Ctrl+Shift+P or Cmd+Shift+P on macOS).
- Open the Command Palette.
- Type
Chameleon to see all available commands.
- Select
Chameleon: Select Lines by Query... (or use the suggested shortcut Ctrl+Shift+L / Cmd+Shift+L).
- Enter your DSL expression in the input box and watch the live preview highlight your matching lines.
- Press
Enter to confirm the selection.
🧠 The Selection DSL
The core of Chameleon Selection is its DSL. It's designed to be intuitive and based on standards you already use daily.
1. Ranges and Intervals
Select lines based on mathematical interval notation.
[7, 12] or [7-12]: From line 7 to 12 (inclusive).
(7, 12]: From line 8 to 12 (7 is exclusive).
[7, 12): From line 7 to 11 (12 is exclusive).
(7, 12): From line 8 to 11 (both exclusive).
[7, ] or [7-]: From line 7 to the end of the document.
[, 12] or [-12]: From the beginning to line 12.
15: Only line 15.
* or all: All lines in the document.
(Optional slicing like Python: [10-20:2] may also be supported for step-based ranges).
2. Content Search
Filter lines based on the text they contain.
"text" or 'text': Select lines containing this exact string.
/regex/: Select lines matching a regular expression. Supports flags like /error/i for case-insensitive search.
Tip: Use a backslash \ to escape characters, e.g., "class=\"active\"" or /path\/relative/.
3. Sequence Modifiers
Select lines based on periodicity (inspired by CSS nth-child).
even: Selects even lines.
odd: Selects odd lines.
nth(3): Every 3 lines (1, 4, 7, 10...).
nth(3, 2): Every 3 lines starting with an offset of 2 (2, 5, 8...).
4. Composition and Logical Operators
Combine different filters and ranges to create highly specific selections.
Precedence Rule: Intersection (&) and Exclusion (-) are evaluated before Union (|), following standard mathematical precedence. Use parentheses () to override.
- Union (OR)
| or ,: Combines sets of lines.
- Example:
[1-5], [10-15] (Lines 1 to 5 AND 10 to 15).
- Intersection (AND)
&: Lines that meet all conditions.
- Example:
[10-50] & /TODO/ (Lines between 10 and 50 that contain "TODO").
- Exclusion (NOT)
- or !: Removes lines from the set.
- Example:
* - /console\.log/ (The entire document except lines with console.log).
- Grouping
(): Controls evaluation order.
- Example:
([1-100] | [200-300]) & /error/ (Lines 1-100 or 200-300 that also contain "error").
🛠️ Extension Commands
| Command |
Description |
Chameleon: Select Lines by Query... |
The main command. Evaluates the query over the whole file and replaces the current selection. |
Chameleon: Filter Selection by Query... |
Applies the query only to the currently selected lines. Useful for progressively narrowing down large selections. (Note: Sequence modifiers like nth(2) will count relative to the selected block). |
Chameleon: Add Lines to Selection... |
Evaluates the query and adds the results to your current selections (Union). |
Chameleon: Remove Lines from Selection... |
Evaluates the query and removes the resulting lines from your current selections. |
Chameleon: Repeat Last Query |
Re-runs your last DSL expression. Great for applying identical patterns across multiple files. |
Chameleon: Select Lines by Word Under Cursor |
Instantly selects all lines containing the word currently under your cursor. |
📖 Recipe Book & Use Cases
Here are some practical examples to get you started quickly:
🧹 Code Cleanup
Scenario: You want to remove all console.log statements from your file.
- Query:
/console\.log/
- Action: Run
Select Lines by Query, then press Delete.
Scenario: You want to find all TODO comments but only in the first 200 lines.
🔍 Log Analysis
Scenario: You have a massive log file and only want to keep lines containing "ERROR", but you want to ignore "DEBUG" and "INFO".
- Query:
/ERROR/ | "Exception" (Select lines with ERROR or Exception)
- Alternative:
* - /DEBUG/ - /INFO/ (Select everything EXCEPT debug and info lines)
📊 Data Processing (CSV / JSON)
Scenario: You have a CSV file and want to select every other line to split the dataset in half.
Scenario: You want to extract all JSON objects that have an "id" field in lines 50 to 150.
- Query:
[50-150] & /"id":/
✂️ Precision Editing
Scenario: You are refactoring a CSS file and want to find all .button classes, but ignore .button-primary.
- Query:
/\.button/ - /\.button-primary/
Scenario: You want to modify imports at the top of your file (lines 1-20) and exports at the bottom (lines 300+), but nothing in between.
⚖️ License & Legal
Ownership
This extension and its source code are the exclusive intellectual property of Juan Manuel Santoyo Ruiz. All rights reserved.
Permitted Use
You are granted a limited right to install and execute this extension within your development environment. You may not decompile, reverse-engineer, modify, or redistribute this software or any portion of its code.
Limitation of Liability
[!IMPORTANT]
The software is provided "as is", without warranty of any kind. The author shall not be held responsible for any errors, data loss, or any other issues that this extension may cause in the user's development environment. In no event shall the author be liable for any claim, damages, or other liability arising from the use of this software.
© 2026 Juan Manuel Santoyo Ruiz. All rights reserved.