moveBy
Move or select text according to a given unit. The units are predefined in the configuration for selection utilities. See below for details on how to define your own units.
Arguments
unit
: The name of the unit to move or select.select
: If true, select the text instead of moving the cursor.value
: The number of units to move or select forward. Use negative numbers to move or select backwards.selectWhole
: If true, move the selection so it starts at the beginning of the unit and ends at the end of the unit. Ifvalue
> 1, multiple units will be selected.selectOneUnit
: LikeselectWhole
, but only one unit is selected when the count is greater than 1, moving to the nth such unit.boundary
: The boundaries to consder when moving. One of "start", "end", "both".selectWhole
withstart
set will select from the beginning of one unit up until the beginning of the next unit.
Defining Units
Units are defined in your configuration file using selection-utilities.motionUnits
. This is a language-specific configuration option, so you can define a different set of units for each language, if you wish. There are two types of units you can define:
Single-line units
These are the simplest and most common units. They are defined by a single regular expression. They have a "name" and a "regex". For example:
{
"selection-utilities.motionUnits": [
{
"name": "word",
"regex": "\\w+"
}
]
}
This would define a unit called "word" that matches one or more word characters.
Multi-line units
These are units that span multiple lines. They are define by one or more regular expressions. They have a "name" and a "regexs" field. When "regexs" is a single regex string, it will match a serires of lines, all of which must match this regex. For example, to define a unit that matches a contiguous series of lines that have no empty lines in between you could do the following.
{
"selection-utilities.motionUnits": [
{
"name": "until",
"regexs": "\\S+"
}
]
}
Alternatively, you can specify multiple regular expressions, in which case the unit is expected to contain a fixed number of lines, where each line matches one of the listed regexes in sequence. For example, section headers that have one line with at least 10 /
characters, followed by a line with // [section name]
, would match the following unit definition:
{
"selection-utilities.motionUnits": [
{
"name": "section",
"regexs": ["^/{10,}$", "^// \S+"]
}
]
}
Default Units
The default units are defined as follows:
{
"selection-utilities.motionUnits": [
{
"name": "BigWord",
"regex": "[^\\s]+"
},
{
"name": "word",
"regex": "(_*[\\p{L}][_\\p{L}0-9]*)|(_+)|([0-9][0-9.]*)|((?<=[\\s\\r\\n])[^\\p{L}^\\s]+(?=[\\s\\r\\n]))"
},
{
"name": "number",
"regex": "[0-9]+"
},
{
"name": "subword",
"regex": "(_*[\\p{L}][0-9\\p{Ll}]+_*)|(_+)|(\\p{Lu}[\\p{Lu}0-9]+_*(?!\\p{Ll}))|(\\p{L})|([^\\p{L}^\\s^0-9])|([0-9][0-9.]*)"
},
{
"name": "subident",
"regex": "(\\p{L}[0-9\\p{Ll}]+)|([0-9][0-9.]*)"
},
{
"name": "paragraph",
"regexs": "\\S+"
},
{
"name": "section",
"regexs": [
".+",
"^.*========+.*$"
]
},
{
"name": "subsection",
"regexs": [
".+",
"^.*(========+|--------+).*$"
]
}
]
}