-
-
Notifications
You must be signed in to change notification settings - Fork 286
Map a key to different commands on different websites
Since v1.88.0, Vimium-C supports a much more powerful runKey command and a special directive of env, and then users may trigger different commands with a same key, on different websites or for different active elements in current page.
-
envis to declare a group of conditions (as an "environment"), and its syntax isenv <name> condition1="..." condition2="..."-
namecan be any string if only it has no white space characters - since v1.88.2, there're 3 supported conditions:
host,elementandfullscreen - the usage of
hostcondition is just like URL patterns of exclusion rules, while when it's a RegExp, it must start with^- since v1.92.0,
iframe: boolean | stringis used to match iframes, whilehostonly uses top frame URLs - before v1.92.0,
hostuse URLs of current frames with one exception: forabout:blankor similar iframes, use a URL of the whole tab instead (so do exclusion patterns)
- since v1.92.0,
- the value of
elementcan be a join of tagName, className and ID, following the syntax of CSS selectors -
fullscreencan be a boolean value, and it only checks fullscreen status caused by JavaScript code, but not status from browser's shortcuts like F11
-
- then
runKeymainly has two options:expectandkeys-
expectcan be a dict mapping environment names to keys, an array of{"env":"...","keys":"...","options"?:{...}}, or a string ofenvName1: keySequences1; env2: keys2(before v1.92.0, replace;with,) - since v1.92,
expectcan also be a list of triplets includingenv,keysand optionaloptions - if an environment matches a current situations, then use its corresponding
keysand the count received byrunKeysto trigger anothermaprule - if no environments match, then trigger the
keysandoptionsparameters ofrunKeyitself
-
-
keysshould be a valid "key sequence" likef,gF,[[,<a-c>and<v-j:i>, or it can be a list of key sequences- if a
keysis only a string and has no space characters, then Vimium C will execute a new key sequence ofrepeating count of "runKey" + keys - if there're spaces in a
keysstring, orkeysis an array of string, then use repeating count ofrunKeyto select an item of it- if the absolute value of repeating count is too large, then show an error and stop
- if the repeating count is negative, then do finding backwards
- since v1.92.0, the delimiter of keys can also be
,
- if a
-
keyscan also be a tree of key sequences, supportingif-then-elsestructures - if
runKeyhas nooptions, then all parameters whose names match`o.${string}`will be collected as itsoptionsparameter
Here's an example of mappings, which is used to move caret on input, <textarea> or <select> smartly (meaing of <c-j:i> can be found in ./Use-in-another-keyboard-layout):
# some syntax work since v1.92.0
env input element="input"
env select element="select"
# env textarea element="textarea"
map <c-j:i> runKey expect={"input":"<v-j1>","select":{"keys":"<v-j2>",options:{}}} keys="<v-j0>"
map <c-k:i> runKey expect=[{"env":"input","keys":"<v-k1>"},{"env":"select","keys":"<v-k2>",options:{}}] keys="<v-k0>"
# map <c-h:i> runKey expect="input:<v-h1>;select:<v-h2>,<v-h2_2>" keys="<v-k0>"
map <v-j0> editText run="auto,forward,line"
map <v-k0> editText run="auto,backward,line"
map <v-j1> editText run="auto,forward,character"
map <v-k1> editText run="auto,backward,character"
map <v-j2> scrollSelect
map <v-k2> scrollSelect dir=-1
Note: <v-***> is also a new syntax since v1.88.0. It focuses on declaring a "fake" composed key to use in mapkey and runKey, and can improve the performance of looking up keys slightly.
Another example showing the runKey command combined with the match option for link hints on a specific website:
env hn host="https://news.ycombinator.com/"
map F runKey expect={"hn":"<v-fhn>"} keys="<v-fd>"
map <v-fd> LinkHints.activateModeToOpenInNewTab
map <v-fhn> LinkHints.activateModeToOpenInNewTab match=".titlelink"
env cBm host=":chrome://bookmarks/"
map f runKey expect=[["cBm","<v-f>",{"clickable":"[role=treeitem]"}]] keys="<v-f>"
map <v-f> LinkHints.activate
This highlights only the actual external links on the Hacker News frontpage that can be opened in a new tab. You could do the same for f, however, if you leave that as it is, you can still use it to highlight the links to comment pages (and perhaps toggle to open them in a new tab using Ctrl in highlight mode).