Open File at Regex-Based Search Match Line in VS Code
ASTER::ACTION::JSON::VS Code File Jump from Regex Match via JSON Action.
This function integrates with VS Code’s CLI (
code -g) to open files at the locations of regex matches.
Search for a string match in a JSON file, retrieve the matched line and column numbers,
and open the file in Visual Studio Code at that exact position.
The code -g option allows you to launch Visual Studio Code from the command line and jump directly to the specified line and column.
powershell.exe -NoExit -Command "code -g './test/urfileof.json:42,8'"Several editors have command-line parsers that allow you to open a file and jump directly to a specified line.
However, there is no unified format specification for this mechanism, and each editor uses its own syntax.
Therefore, this command is exclusive to Visual Studio Code.
-
To use it, the VS Code command-line tool must be available in your PATH.
-
String search can be performed using regular expressions.
-
The search targets UTF-8 encoded strings.
-
You can retrieve only the first line of the search result.
-
A line offset can be specified to skip certain lines during the search.
Parameter.1
File path
"./file/utf8EncodedText.json" ⚠️ If the specified directory path does not exist, all processing will be aborted.
Parameter.2
Search Query ( Regex )
"urSearchKey" Parameter.3
Line Offset Value
100This is an offset value that allows the search to skip from the beginning up to the specified line, and then start the search from that line onward.
Since the value is converted to an unsigned integer (size_t), entering a negative number such as -100 will wrap around according to the modulo conversion rules, producing 4294967196.