-
-
Couldn't load subscription status.
- Fork 287
Trigger commands in an input box
If a user wants to keep Vimium C's commands usable even when an input box is focused, here's some advices:
press Esc or Ctrl+[ to "blur" input boxes and then Vimium C will go back to normal mode and consume following keys
-
<esc>and<c-[>can be mapped. For example,mapkey <c-]> <esc>will make Ctrl+] (during Vimium C consumes it) work like Esc - there's a command named
switchFocus, and you may use it to re-focus the most-recently-focused input box, when you have pressed Esc
map some keys which contains F1 ~ F12
- Vimium C will keep such keys, whose main key is F1~F12, usable even in a default insert mode
- of course not in the insert mode entered by the command
enterInsertMode
- of course not in the insert mode entered by the command
- For example,
map <s-f8> LinkHints.activatemakes Shift+F8 always trigger LinkHints mode - But
map <f8>f LinkHints.activatecan not be triggered in a default insert mode, because the second key,f, is not in F1~F12- if press
<f8>and thenf, then<f8>will be consumed by Vimium C, andfwill be passed through to a input box itself.
- if press
configure global shortcuts on chrome://extensions/shortcuts or about:addons (Firefox)
- command shortcuts configured here are always usable, unless some of browser's built-in shortcuts have higher priorities.
- if the command you want is not in the list, you may setup "User Customized" 1 and 2, and add something like
shortcut userCustomized1 command="goBack"into "Custom key mappings" on Vimium C Options page - if the 2 placeholders are not enough, there's an assistant extension named Shortcut Forwarding Tool to let you setup more.
- on Firefox, please visit
about:addonsmanually, click thesettingsicon button and clickManage Extension Shortcuts
-
long keys ending with
:ialso work in a plain insert mode, since v1.84.1- for example,
map <c-j:i> editText run="auto,forward,line"will move caret down by a line, only in insert mode - but they do not work in any global insert mode of
enterInsertMode
- for example,
-
long keys starting with
v-always work in a plain insert mode, since v1.92.0
Note: this section only works since v1.97.0.
The passNextKey support a parameter named normal, just as in Vimium, and since v1.97.0 it can skip the check of insert mode**, so you may add a mapping like this:
map <f1> passNextKey normal count=10
And then, if press <f1> in input, you can trigger all key mappings, whether it's allowed in insert mode or not, for up to 10 times. If you want to exit this, an <esc> is just enough.
The editText command support run="<text-command> [... "," [spaces] <text-command>]":
- a
<text-command>must include 1-3 units; if it is not the last text command, it must include 3 units- in a text command, this order of units is
cmd, arg1, arg2 - when
arg2is omitted, it means an empty string
- in a text command, this order of units is
- when
cmdisexec,arg1andarg2are passed todocument.execCommand(arg1, false, arg2) - when
cmdisreplace, replace currently selected text witharg1-
arg1can be URL-encoded, and it will be decoded before inserting into an input box -
arg1can include"$s"(or%s) which refers the currently selected text
-
- when
cmdiscollapse, make a current selection collapse- if
arg1isend, then collapse into the end; otherwise collapse into the start
- if
- when
cmdisauto,extendormove, then modify a current selection- if
cmdisauto, it meansextendwhen a selection has a range, or otherwisemove -
arg1can beforward,backwardorcount(ifcommand count > 0thenforward; otherwisebackward) -
arg2should be a valid granularity likecharacter,word,sentence,lineorlineboundary
- if
Here're some examples:
# make selected text italic (e.g. in a MarkDown document)
map <c-b:i> editText run="replace,_$s_"
# delete a word starting from a current cursor, just like in Bash shell
map <a-f:i> editText run="extend,forward,word,exec,delete"
editText also supports a boolean dom. By default it only executes its run when an editable input / textarea is focused,
but when dom is true, it also executes on common content-editable elements.
More examples can be seen in https://github.com/gdh1995/vimium-c/issues/114#issuecomment-581125416 (in English) and https://github.com/gdh1995/vimium-c/issues/386#issuecomment-876404555 (in Chinese).
Here's an example to simulate a pair of Escape keyboard events to trigger actions of a page itself and other extensions:
mapKey <c-]> <v-esc_pair>
# v1.96.* has a bug, so `keys` need to be `"+esc+-esc"`, since v1.97 `keys="esc-esc"` should work
map <v-esc_pair> runKey keys="+esc+-esc"
map <v-esc> dispatchEvent type="keydown" code="Escape" key="Escape" keyCode=27
This method requires the command dispatchEvent, which is available since v1.92.4 .
Since v1.96.0, Vimium C has supported Compatibility of Escape, and you may specify a list of CSS selectors to make Vimium C pass Escape keys to pages when it blurs a target input element.