Filter LinesThis extension allows to you to filter lines of the current document by a string or a regular expression. It is basically a port of Filter Lines package for Sublime Text. (the access log used for this illustration is borrowed here) Available commandsAll of the following commands are available via Ctrl-Shift-P.
* Use cmd instead of ctrl on Mac "Regex" commands accept any regular expression valid in JavaScript, except that you cannot really match multiple lines.
See MDN for syntax reference, but
keep in mind that you only need to enter the inner part of the regex without the enclosing slashes ( "Context" commands additionally prompt you for the number of lines to include/exclude around a matching line, similarly to
Available settings
If you are using Settings UI, you will find these settings under "Filter Lines" section. Under the hood: Available commands idsYou can use these command ids to make your own keybindings. #
|
Argument | Possible values | Default value | Description |
---|---|---|---|
search_type |
"regex" or "string" |
"regex" |
Defines the search type. |
invest_search |
true or false |
false |
Defines the action type. By default the "Include" action is performed. Set invest_search to true to perform the "Exclude" action. |
with_context |
true or false |
false |
Controls whether to prompt for context. |
context |
any non-negative number | — | Defines the number of leading and trailing context lines. Only takes effect if with_context is false . |
before_context |
any non-negative number | — | Defines the number of leading context lines, overriding context if it is given. Only takes effect if with_context is false . |
after_context |
any non-negative number | — | Defines the number of trailing context lines, overriding context if it is given. Only takes effect if with_context is false . |
# filterLines.filterLines
Performs the action specified in the arguments with the given search string. Arguments:
Argument | Possible values | Default value | Description |
---|---|---|---|
search_type |
"regex" or "string" |
"regex" |
Defines the search type. |
invest_search |
true or false |
false |
Defines the action type. By default the "Include" action is performed. Set invest_search to true to perform the "Exclude" action. |
needle |
any string | "" |
Defines the search string, as in the "needle in a haystack" idiom. |
context |
any non-negative number | — | Defines the number of leading and trailing context lines. |
before_context |
any non-negative number | — | Defines the number of leading context lines, overriding context if it is given. |
after_context |
any non-negative number | — | Defines the number of trailing context lines, overriding context if it is given. |
Differences from the original Filter Lines
- Folding is not supported due not VS Code API limitations.
- Menu items are not provided, again due to VS Code API limitations.
- With
"preserveSearch": true
the search string is stored in memory rather than on disk and is cleared as soon as the VS Code window is closed. - With
"lineNumbers": true
line numbers are 1-based, not 0-based. - With
"lineNumbers": true
line numbers are appended even when the search is inverted (that is, when an "Exclude…" command is used).
You can find this extension both in the Visual Studio Marketplace and in the Open VSX Registry. Happy filtering!