Precise Line Range SelectionSelect text ranges in Visual Studio Code by entering line numbers with optional secondary coordinates. The extension supports:
InstallationVisual Studio CodeInstall Precise Line Range Selection from the Visual Studio Code Extensions view:
Command LineYou can also install the extension using the VS Code CLI:
To uninstall it:
UsageRun: Precise Line Range Selection: Select Line Range from the Command Palette or editor context menu, or use the default keybinding:
Enter a range using:
The two line specifiers are separated by whitespace. Examples:
A hyphen is used only as the sign of a negative number. It is not a range separator. Line NumbersLine numbers are always 1-based. For example:
refers to the first line. Negative line numbers count backward from the end of the document:
refers to the last line,
to the second-to-last line, and so on. After negative indexing is resolved, out-of-range line numbers are clipped to the document. For example, a value before the first line resolves to line 1, while a value beyond the last line resolves to the last line. Coordinate ModesThe optional secondary coordinate is controlled by:
Supported values are:
The default is:
Both modes operate on Unicode grapheme clusters, which correspond to user-perceived characters rather than UTF-16 code units or individual Unicode code points. For example, the line:
contains three user-perceived characters:
Likewise, a combining sequence such as:
where the displayed character may internally consist of Multi-code-point emoji sequences are also treated as a single character when Unicode grapheme segmentation defines them as one grapheme cluster. Character ModeConfigure:
The secondary coordinate is a 1-based user-perceived character number. Characters are determined using Unicode grapheme-cluster boundaries. Explicit character endpoints are inclusive. For:
the characters are:
For example:
selects characters 1 through 3 on line 2:
Likewise:
selects the same text backward. If both explicit endpoints refer to the same character:
that character is selected. For a line such as:
the displayed Column ModeConfigure:
The secondary coordinate is a 1-based logical text position between user-perceived characters. Column 1 is the beginning of the line. Every Unicode grapheme cluster advances the logical column by exactly one. For:
the logical columns are:
For:
the logical columns are:
Likewise, for:
the logical columns are:
A user-perceived character therefore advances the logical column by one regardless of how many Unicode code points or UTF-16 code units are required to represent it internally. Tabs behave the same way: a literal tab advances the logical column by one. This mode does not use VS Code's visual/status-bar column calculation and is independent of If both explicit endpoints specify the same column:
both endpoints identify the same text position, so there is nothing to select and the command performs no selection. An empty line has one valid logical column:
which is both the beginning and end of that line. Negative CoordinatesNegative secondary coordinates count backward from the end of the relevant coordinate domain. In character mode, a line containing
so:
means the last character. In column mode, the same line has valid logical columns:
so:
means the final position after the last character. After negative indexing is resolved, coordinates outside the valid range are clipped. Omitted CoordinatesAn omitted secondary coordinate refers to the appropriate line boundary based on selection direction. For a forward selection:
For a backward selection:
For example:
selects forward from the beginning of line 5 through the end of line 10. Likewise:
selects backward from the end of line 10 to the beginning of line 5. Omitted End SpecifierIf the entire end specifier is omitted, the selection extends to the end of the document. For example:
selects from the beginning of line 13 through the end of the document. In character mode:
selects from character 5 on line 13, including that character, through the end of the document. In column mode:
selects from logical column 5 on line 13 through the end of the document. Selection DirectionDirection is determined after line numbers and usable explicit coordinates have been normalized and clipped. 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 endpoints are on the same resolved line and both explicit coordinates are available:
If either coordinate is omitted or otherwise unavailable on the same line, the selection defaults to forward. The original direction is preserved in the resulting VS Code selection, including which endpoint is the active cursor position. Empty LinesCharacter mode has no actual character number on an empty line. If an explicit character number resolves to an empty line, it is treated as having no usable character target. The final endpoint is then resolved to the appropriate line boundary after selection direction is known. Column mode has exactly one valid coordinate on an empty line:
Both the beginning and end of an empty line map to the same physical VS Code position. If both final endpoints resolve to the same position, the command performs no selection. Input ValidationThe input must contain one or two line specifiers:
Each numeric component must be a non-zero signed integer. Valid examples include:
Zero is not valid:
Leading zeros are allowed and are normalized numerically. The input box performs live validation while typing and only accepts a complete value that matches the range grammar. Configuration
|
| Value | Meaning |
|---|---|
character |
1-based user-perceived character numbers with inclusive explicit endpoints |
column |
1-based logical text positions between user-perceived characters |
Example:
{
"precise-line-range-selection.coordinateMode": "column"
}
Unicode and VS Code Positions
VS Code's Position.character value is a UTF-16 code-unit offset.
The extension does not expose those raw offsets to the user.
Instead, it analyzes the relevant lines using Unicode grapheme clusters and translates the configured user-facing coordinate semantics into the UTF-16 offsets required by the VS Code API.
This keeps coordinates aligned with user-perceived character boundaries, including combining sequences, surrogate-pair characters such as many emoji, and multi-code-point grapheme clusters.
Requirements
Visual Studio Code:
1.68.0 or newer
Development
Install dependencies:
npm install
Package the extension:
npm run package
Other versioned publishing scripts are available through package.json.
License
This project is licensed under the MIT License.