-
-
Notifications
You must be signed in to change notification settings - Fork 260
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.activate
makes Shift+F8 always trigger LinkHints mode - But
map <f8>f LinkHints.activate
can 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, andf
will 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:addons
manually, click thesettings
icon button and clickManage Extension Shortcuts
-
long keys ending with
:i
also 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
arg2
is omitted, it means an empty string
- in a text command, this order of units is
- when
cmd
isexec
,arg1
andarg2
are passed todocument.execCommand(arg1, false, arg2)
- when
cmd
isreplace
, replace currently selected text witharg1
-
arg1
can be URL-encoded, and it will be decoded before inserting into an input box -
arg1
can include"$s"
(or%s
) which refers the currently selected text
-
- when
cmd
iscollapse
, make a current selection collapse- if
arg1
isend
, then collapse into the end; otherwise collapse into the start
- if
- when
cmd
isauto
,extend
ormove
, then modify a current selection- if
cmd
isauto
, it meansextend
when a selection has a range, or otherwisemove
-
arg1
can beforward
,backward
orcount
(ifcommand count > 0
thenforward
; otherwisebackward
) -
arg2
should be a valid granularity likecharacter
,word
,sentence
,line
orlineboundary
- 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.