Advanced Line Range SelectionAdvanced Line Range Selection is a focused Visual Studio Code extension for selecting exact text ranges using human-readable line coordinates. It supports:
InstallationInstall Advanced Line Range Selection from the Visual Studio Code Extensions view, or use:
To uninstall it:
Command
The normal UI entry points are available when a text editor has focus. UsageRun Advanced Line Range Selection: Select Line Range and enter one or more ranges separated by commas. Each range contains either one line specifier or a start/end pair:
A line specifier has one of these forms:
A
For The
Multiple ranges use:
Each non-empty range creates one VS Code selection. Range order is preserved, so the first resulting selection is the primary selection. Basic examplesThe following examples assume the default
When the end specifier of a range is omitted entirely, that range extends to the end of the document. Input SyntaxLine referencesEvery line specifier begins with a line reference. A line reference can be either an absolute line number or a current-line-relative reference. Absolute line numbersAn absolute line number is a non-zero signed integer:
Leading zeros are allowed:
Zero is invalid:
Negative absolute line numbers count backward from the end of the document:
After negative indexing is resolved, out-of-bounds absolute line numbers are clipped to the document. Current-line-relative references
The offset form requires an explicit sign and a non-zero integer magnitude. Leading zeros are allowed:
Use bare
All A relative reference is calculated from that captured line and then clipped directly to the document bounds. It is not reinterpreted as negative indexing from the end of the document. A current-line reference can use either secondary-position syntax directly:
Multiple rangesOne command can contain multiple comma-separated ranges:
Each non-empty range is parsed independently and creates one selection. Range order is preserved. The first resulting selection becomes VS Code's primary selection. Empty comma-separated parts are ignored, so:
contains two non-empty ranges. Every non-empty range must be complete and valid before the input can be accepted. Integer
|
| Value | Behavior |
|---|---|
nearest |
Select the nearest grapheme boundary. Equal-distance ties select the boundary after the requested position. |
before |
Select the nearest grapheme boundary at or before the requested position. |
after |
Select the nearest grapheme boundary at or after the requested position. |
The default is:
"advanced-line-range-selection.proportionSnap": "nearest"
If the requested position effectively matches an existing grapheme boundary, that boundary is used regardless of the snapping mode.
An empty line has only one boundary, so every proportional position resolves to that boundary.
Omitted Secondary Positions
A line specifier does not need a character, column, or proportional position; this applies to both absolute and @ line references.
For example:
13 20
contains two line-only specifiers.
An omitted secondary position is resolved only after the selection direction is known.
For a forward selection:
- omitted start position -> beginning of the start line;
- omitted end position -> end of the end line.
For a backward selection:
- omitted start position -> end of the start line;
- omitted end position -> beginning of the end line.
This makes line-only ranges symmetric:
13 20
and:
20 13
select the same text with opposite selection directions.
When both resolved line numbers are the same and at least one endpoint does not provide a usable explicit target, the selection is treated as forward.
Selection Direction
Direction is determined after line numbers and explicit secondary positions have been resolved.
The rules are:
- If the resolved start line is before the resolved end line, the selection is forward.
- If the resolved start line is after the resolved end line, the selection is backward.
- If both resolved lines are the same and both endpoints have explicit usable targets, their positions within the line determine the direction.
- Equality is considered forward.
- If both resolved lines are the same and either endpoint has no usable explicit target, the selection is forward.
Character targets and boundary targets can be mixed on the same line.
Their ordering follows:
line start
character 1
boundary after character 1
character 2
boundary after character 2
...
line end
This allows character coordinates and boundary-based column or proportional positions to determine direction consistently.
For each range, the first resolved endpoint becomes that VS Code selection's anchor and the second becomes its active endpoint.
When multiple ranges are supplied, their resulting selections are assigned to editor.selections in input order. VS Code then applies its normal multiple-selection behavior, including its configured handling of overlapping selections.
Empty Lines
An empty line contains zero grapheme clusters but still has one grapheme boundary.
The coordinate types behave as follows:
- character mode has no valid explicit character;
- column mode has exactly one valid column, column
1; - every proportional position resolves to the line's only boundary.
If an explicit character coordinate resolves to an empty line, there is no character to target. That endpoint is therefore treated like an omitted secondary position.
If both final VS Code positions for a range are identical, that zero-length range is skipped. If every range is skipped, the command performs no selection change.
A completely empty document is handled by the same rules.
Input Validation
Interactive use employs a managed VS Code input box with separate live validation and strict acceptance.
Live validation
As you type, the extension distinguishes between:
- complete valid input;
- incomplete input that can still become valid;
- structurally invalid input.
Incomplete input uses informational guidance such as:
Keep typing...
rather than an error state.
With multiple ranges, a transitional incomplete state is allowed only in the last non-empty range. Once another non-empty range has been started, every earlier range must already be complete.
Strict acceptance
Pressing Enter only accepts the input when every non-empty comma-separated range matches the complete grammar.
Leading and trailing whitespace around the complete input and individual ranges are ignored. Empty comma-separated parts are ignored.
Leading zeros are accepted for non-zero integer components:
005
+005
-005
005:003
005:-003
@+005
@-003
The following integer forms are invalid:
0
+0
-0
5:
@+0
@-0
Bare @ is valid and means zero relative line offset.
Zero is valid in proportional syntax:
5.0
@.0
A bare proportional dot is also complete input:
5.
@.
Input History
Interactive use keeps a persistent, bounded history for each document.
History is navigated directly from the input box with the Previous history entry and Next history entry buttons. The buttons appear when compatible history exists for the current file.
Each history entry represents the complete accepted comma-separated command input, not the individual ranges inside it.
History entries are stored in canonical form:
- integer absolute line numbers and
:coordinates are normalized numerically; @remains@;- positive relative offsets keep the required
+, while their integer magnitude is normalized; - negative relative offsets retain
-, with leading zeros removed; - proportional digits remain textual;
- range order is preserved.
For example:
+0005:+003 0010, @-0002.2500
is recalled as:
5:3 10, @-2.2500
Duplicate history entries are moved to the newest position instead of being stored repeatedly.
History is coordinate-mode-aware:
- an entry containing at least one
:coordinate is available only when the currentcoordinateModematches the mode under which it was executed; - an entry containing no
:coordinates is available in both character and column modes.
When history navigation starts, the current editable text is preserved as a draft. Moving forward past the newest history entry restores that draft.
Only successfully executed interactive inputs are added to this history. Programmatic command arguments are not added.
Programmatic Invocation
The command can also be invoked directly with an input string.
When a string argument is supplied, the command skips the input box and sends the string through the same parser and range-resolution logic used by interactive input.
The argument can use absolute line references, @ references, secondary coordinates, proportional positions, and multiple comma-separated ranges.
For example, another extension can invoke:
await vscode.commands.executeCommand(
"advanced-line-range-selection.selectLineRange",
"13:2 20.75, @-2 @+2",
);
A keybinding can also pass a fixed input:
{
"key": "ctrl+alt+r",
"command": "advanced-line-range-selection.selectLineRange",
"args": "13:2 20.75, @-2 @+2",
"when": "editorTextFocus"
}
If no argument is supplied, the normal interactive input box is shown.
If the supplied argument is not a string, or if any non-empty range in the string does not match the accepted input grammar, the command performs no selection change.
Programmatic invocation operates on the current active text editor. If there is no active text editor, the command returns without making a change.
Programmatic invocations do not add entries to the interactive input history.
Configuration
Coordinate mode
Setting:
advanced-line-range-selection.coordinateMode
Default:
character
Available values:
| Value | Meaning |
|---|---|
character |
: numbers identify 1-based grapheme characters. Explicit character endpoints are inclusive. |
column |
: numbers identify 1-based grapheme boundaries. |
Proportional snapping
Setting:
advanced-line-range-selection.proportionSnap
Default:
nearest
Available values:
| Value | Meaning |
|---|---|
nearest |
Snap to the nearest grapheme boundary; ties snap after. |
before |
Snap to the nearest boundary at or before the requested position. |
after |
Snap to the nearest boundary at or after the requested position. |
Both settings are resource-scoped.
Keyboard Shortcut
| Platform | Shortcut |
|---|---|
| Windows / Linux | Ctrl+[ then Ctrl+] |
| macOS | Cmd+[ then Cmd+] |
The shortcut is active when a text editor has focus.
Other Ways to Run the Command
The command is also available from:
- Command Palette ->
Advanced Line Range Selection: Select Line Range - Editor context menu ->
Select Line Range
The editor context-menu entry is placed in the selection group.
Requirements
- Visual Studio Code
1.68.0or later.
The extension has no external runtime dependencies.
Development
Install development dependencies:
npm install
Package the extension:
npm run package
Publish the current version:
npm run publish
The package manifest also provides semantic-version publishing scripts:
npm run publish:patch
npm run publish:minor
npm run publish:major
Publishing requires the normal Visual Studio Marketplace publisher credentials and vsce authentication.
Repository
License
This project is licensed under the MIT License.
See LICENSE for details.
Author
- Name: Or Fadida
- Email: or@fadida.net
- GitHub: orfadida2000
- Marketplace: orfadida