]> git.donarmstrong.com Git - dactyl.git/blob - common/locale/en-US/map.xml
Import 1.0 supporting Firefox up to 14.*
[dactyl.git] / common / locale / en-US / map.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <?xml-stylesheet type="text/xsl" href="dactyl://content/help.xsl"?>
3
4 <!DOCTYPE document SYSTEM "dactyl://cache/modes.dtd">
5
6 <document
7     name="map"
8     title="&dactyl.appName; Key Mappings"
9     xmlns="&xmlns.dactyl;"
10     xmlns:dactyl="&xmlns.dactyl;"
11     xmlns:html="&xmlns.html;">
12
13 <h1 tag="keyboard-shortcuts">Keyboard shortcuts and commands</h1>
14 <toc start="2"/>
15
16 <p>
17     &dactyl.appName; provides a number of commands to change the
18     behavior of key presses. This can mean anything from
19     automatically substituting one key for another or automatically
20     replacing one typed word for another, to launching a dialog or
21     running a command.
22 </p>
23
24 <h2 tag="key-mapping mapping map macro">Key mapping</h2>
25
26 <p>
27     Key mappings are the most basic means &dactyl.appName; provides
28     for altering the actions of key presses. Each key mapping is
29     associated with a mode, such as <link topic="insert-mode">Insert</link>,
30     <link>Normal</link>, or
31     <link topic="command-line-mode">Command Line</link>, and only
32     has effect when that mode is active. Although each mode has a
33     full suite of internal mappings, they may be easily augmented,
34     altered, or removed with the <ex>:map</ex> command and its
35     variants. These commands, in essence, allow the user to quickly
36     substitute one sequence of key presses for another.
37     For instance,
38 </p>
39
40 <code><ex>:map <k name="F2" link="false"/></ex> <ex>:styletoggle</ex> <em>-name</em> <k name="A-Tab" link="c_&lt;Tab>"/></code>
41
42 <p>
43     causes “<tt><ex>:styletoggle</ex> <em>-name</em> <k name="A-Tab" link="c_&lt;Tab"/></tt>” to be typed out
44     whenever <k name="F2" link="false"/> is pressed, providing a way to toggle
45     a tab-completed named user style.
46 </p>
47
48 <p>
49     You can also map keys to <link topic="ex-scripts">Ex</link> or
50     <link topic=":js">JavaScript</link> commands, see the
51     <link topic="map-examples">examples</link>.
52 </p>
53
54 <p tag=":map-modes">
55     Standard key mapping commands are provided for the five most
56     common modes,
57 </p>
58
59 <dl dt="width: 8em;">
60     <dt>n</dt> <dd>Normal mode: When browsing normally</dd>
61     <dt>v</dt> <dd>Visual mode: When selecting text with the cursor keys</dd>
62     <dt>i</dt> <dd>Insert mode: When interacting with text fields on a website</dd>
63     <dt>t</dt> <dd>Text Edit mode: When editing text fields in Vim-like Normal mode</dd>
64     <dt>c</dt> <dd>Command Line mode: When typing into the &dactyl.appName; command line</dd>
65     <dt>o</dt> <dd>Operator mode: When moving the cursor</dd>
66 </dl>
67
68 <p>
69     The ordinary <ex>:map</ex> command adds mappings for Normal and Visual
70     mode. In order to map key bindings in a different mode, any of the mapping
71     commands may be prefixed with one of the above letters. For instance,
72     <ex>:imap</ex> creates a new key mapping in Insert mode, while
73     <ex>:cunmap</ex> removes a key mapping from Command Line mode. Other modes
74     can be specified using the <em>-modes</em> option described below.
75 </p>
76
77 <warning>
78     It is important to note that mappings are <em>not</em>
79     automatically saved between sessions. In order to preserve them,
80     they must either be added to your <tt><t>&dactyl.name;rc</t></tt> or
81     saved via the <ex>:mk&dactyl.name;rc</ex> command.
82 </warning>
83
84 <p tag="modes">
85     The following tree represents all of the modes understood by
86     dactyl. Mappings for a mode also apply to its children and
87     descendants. So a mapping in the Base mode, for instance, is
88     also active in Normal and Ex mode.
89 </p>
90
91 &modes.tree;
92
93 <h3 tag=":map-commands">Map commands</h3>
94
95 <item>
96     <tags>:map</tags>
97     <spec>:map <a>lhs</a> <a>rhs</a></spec>
98     <tags>:nm :nmap</tags>
99     <spec>:nm<oa>ap</oa> <a>lhs</a> <a>rhs</a></spec>
100     <tags>:vm :vmap</tags>
101     <spec>:vm<oa>ap</oa> <a>lhs</a> <a>rhs</a></spec>
102     <tags>:im :imap</tags>
103     <spec>:im<oa>ap</oa> <a>lhs</a> <a>rhs</a></spec>
104     <tags>:tm :tmap</tags>
105     <spec>:tm<oa>ap</oa> <a>lhs</a> <a>rhs</a></spec>
106     <tags>:cm :cmap</tags>
107     <spec>:cm<oa>ap</oa> <a>lhs</a> <a>rhs</a></spec>
108     <description>
109         <p>
110             Map the <t>key-sequence</t> <a>lhs</a> to <a>rhs</a> for
111             the applicable mode(s). The keys of <a>rhs</a> respect
112             user-defined mappings, so the following will result in
113             an infinite loop,
114         </p>
115         <code><ex>:map a b</ex>
116 <ex>:map b a</ex></code>
117         <p>
118             In order to avoid this shortcoming, the <ex>:noremap</ex> command
119             or the <em>-builtin</em> option may be used.
120         </p>
121     </description>
122 </item>
123
124 <p tag=":map-overview">
125     Below is an overview of which modes each map command applies to:
126 </p>
127
128 <dl dt="width: 20em;">
129     <dt>:map   :unmap</dt>  <dd>Normal and Visual modes</dd>
130     <dt>:nmap  :nunmap</dt> <dd>Normal mode</dd>
131     <dt>:vmap  :vunmap</dt> <dd>Visual mode</dd>
132     <dt>:imap  :iunmap</dt> <dd>Insert mode</dd>
133     <dt>:tmap  :tunmap</dt> <dd>Text Edit mode</dd>
134     <dt>:cmap  :cunmap</dt> <dd>Command Line mode</dd>
135 </dl>
136
137 <note>
138     The <em>-modes</em> option, described below, provides a more flexible way
139     to specify the applicable modes.
140 </note>
141
142 <h3 tag=":map-options">Map options</h3>
143 <p>
144     Any of the map commands may be given the following options:
145 </p>
146
147 <dl dt="width: 12em;">
148     <dt></dt> <dd></dd>
149
150     <dt>-arg</dt> <dd>Accept an argument after the requisite key press. Sets the <tt>arg</tt> parameter to the result. (short name <em>-a</em>)</dd>
151     <dt>-builtin</dt> <dd>Execute this mapping as if there were no user-defined mappings. (short name <em>-b</em>)</dd>
152     <dt>-count</dt> <dd>Accept a count before the requisite key press. Sets the <tt>count</tt> parameter to the result. (short name <em>-c</em>)</dd>
153     <dt>-description</dt> <dd>A description of this mapping. (short name <em>-d</em>)</dd>
154     <dt>-ex</dt> <dd>Execute <a>rhs</a> as an Ex command rather than keys. (short name <em>-e</em>)</dd>
155     <dt>-group=<a>group</a></dt> <dd>Add this command to the given <t>group</t> (short name <em>-g</em>). When listing commands this limits the output to the specified group.</dd>
156     <dt>-javascript</dt> <dd>Execute <a>rhs</a> as JavaScript rather than keys. (short names <em>-js</em>, <em>-j</em>)</dd>
157     <dt>-literal=<a>n</a></dt> <dd>Parse the <a>n</a>th argument without specially processing any quote or meta characters. (short name <em>-l</em>)</dd>
158     <dt>-modes=<a>modes</a></dt> <dd>Create this mapping in the given modes. (short names <em>-mode</em>, <em>-m</em>)</dd>
159     <dt>-nopersist</dt> <dd>Do not save this mapping to an auto-generated rc file. (short name <em>-n</em>)</dd>
160     <dt>-silent</dt> <dd>Do not echo any generated keys to the command line. (short name <em>-s</em>, also <em>&lt;silent></em> for Vim compatibility)</dd>
161 </dl>
162
163 <item>
164     <tags>:no :noremap</tags>
165     <spec>:no<oa>remap</oa> <a>lhs</a> <a>rhs</a></spec>
166     <tags>:nno :nnoremap</tags>
167     <spec>:nno<oa>remap</oa> <a>lhs</a> <a>rhs</a></spec>
168     <tags>:vno :vnoremap</tags>
169     <spec>:vno<oa>remap</oa> <a>lhs</a> <a>rhs</a></spec>
170     <tags>:ino :inoremap</tags>
171     <spec>:ino<oa>remap</oa> <a>lhs</a> <a>rhs</a></spec>
172     <tags>:tno :tnoremap</tags>
173     <spec>:tno<oa>remap</oa> <a>lhs</a> <a>rhs</a></spec>
174     <tags>:cno :cnoremap</tags>
175     <spec>:cno<oa>remap</oa> <a>lhs</a> <a>rhs</a></spec>
176     <description>
177         <deprecated>These aliases are deprecated. The <em>-builtin</em> flag
178             should be used in their stead.</deprecated>
179         <p>
180             Map the <t>key-sequence</t> <a>lhs</a> to <a>rhs</a> for
181             the applicable mode(s). The keys in <a>rhs</a> do not
182             respect user-defined key mappings, so the following
183             effectively reverses the default meanings of the keys
184             <k>d</k> and <k>D</k>
185         </p>
186         <code><ex>:noremap d D</ex>
187 <ex>:noremap D d</ex></code>
188     </description>
189 </item>
190
191 <item>
192     <spec>:unmap <a>lhs</a></spec>
193     <tags>:unm :unmap</tags>
194     <spec>:unmap!</spec>
195     <spec>:nun<oa>map</oa> <a>lhs</a></spec>
196     <tags>:nun :nunmap</tags>
197     <spec>:nun<oa>map</oa>!</spec>
198     <spec>:vun<oa>map</oa> <a>lhs</a></spec>
199     <tags>:vun :vunmap</tags>
200     <spec>:vun<oa>map</oa>!</spec>
201     <spec>:iu<oa>nmap</oa> <a>lhs</a></spec>
202     <tags>:iu :iunmap</tags>
203     <spec>:iu<oa>nmap</oa>!</spec>
204     <spec>:tu<oa>nmap</oa> <a>lhs</a></spec>
205     <tags>:tu :tunmap</tags>
206     <spec>:tu<oa>nmap</oa>!</spec>
207     <spec>:cu<oa>nmap</oa> <a>lhs</a></spec>
208     <tags>:cu :cunmap</tags>
209     <spec>:cu<oa>nmap</oa>!</spec>
210     <description>
211         <p>Remove the mapping of <a>lhs</a> (or all mappings if <oa>!</oa> is
212             given) for the applicable mode(s).</p>
213     </description>
214 </item>
215
216 <item>
217     <spec>:map</spec>
218     <spec>:nm<oa>ap</oa></spec>
219     <spec>:vm<oa>ap</oa></spec>
220     <spec>:im<oa>ap</oa></spec>
221     <spec>:tm<oa>ap</oa></spec>
222     <spec>:cm<oa>ap</oa></spec>
223     <description>
224         <p>
225             List all mappings for the applicable mode(s). Mappings are
226             partitioned into <t>groups</t>.
227         </p>
228     </description>
229 </item>
230
231 <item>
232     <tags>:map_l</tags>
233     <spec>:map <a>lhs</a></spec>
234     <tags>:nmap_l</tags>
235     <spec>:nm<oa>ap</oa> <a>lhs</a></spec>
236     <tags>:vmap_l</tags>
237     <spec>:vm<oa>ap</oa> <a>lhs</a></spec>
238     <tags>:imap_l</tags>
239     <spec>:im<oa>ap</oa> <a>lhs</a></spec>
240     <tags>:tmap_l</tags>
241     <spec>:tm<oa>ap</oa> <a>lhs</a></spec>
242     <tags>:cmap_l</tags>
243     <spec>:cm<oa>ap</oa> <a>lhs</a></spec>
244     <description>
245         <p>List all mappings starting with <a>lhs</a> for the applicable mode(s).</p>
246     </description>
247 </item>
248
249 <h3 tag=":map-timeout map-timeout">Mapping timeout</h3>
250 <p>
251     When &dactyl.appName; receives a key event that has a separate binding and
252     at the same time is part of a key chain, values of the <o>timeout</o> and
253     <o>timeoutlen</o> options are used to decide what to do. See the
254     documentation of those options for more information.
255 </p>
256
257 <h3 tag="key-notation key-sequence">Key sequences</h3>
258
259 <p>
260     Most keys in key sequences are represented simply by the
261     character that you see on the screen when you type them.
262     However, as a number of these characters have special meanings,
263     and a number of keys have no visual representation, a special
264     notation is required.
265 </p>
266
267 <ul>
268     <li>
269         The first argument to the <ex>:map</ex> commands must be
270         <link topic="quoting">quoted</link> if it contains spaces,
271         quotation marks or back-slashes. A space may additionally be
272         typed as <k name="Space"/>.
273     </li>
274     <li key="&lt;lt>">
275         As special key names start with the <em>&lt;</em> character,
276         a literal &lt; must be typed as <k name="lt" link="false"/>.
277     </li>
278     <li>
279         <k name="Left"/>, <k name="Right"/>, <k name="Up"/>,
280         and <k name="Down"/> represent the standard arrow keys.
281     </li>
282     <li>
283         <k name="CapsLock" link="false"/>, <k name="NumLock" link="false"/>, <k name="Insert"/>
284         <k name="Del" link="false"/>, <k name="Tab"/>, <k name="PageUp"/>,
285         <k name="PageDown"/>, and <k name="Esc"/> work as
286         expected.
287    </li>
288     <li>
289         <k name="Return" link="false"/> or <k name="CR"/> represent the carriage
290         return key.
291     </li>
292     <li><k name="BS" link="false"/> represents the backspace key.</li>
293     <li><k name="F1"/> through <k name="F12" link="false"/> work as expected.</li>
294     <li>
295         <k name="K0" link="false"/> through <k name="K9" link="false"/> represent keys on the
296         numeric keypad.
297     </li>
298     <li>
299         <k name="Uxxxx" link="false"/>, where <em>xxxx</em> is any 4 hexadecimal
300         digits, represents the character at that Unicode codepoint.
301         For instance, <k name="U263a" link="false"/> represents ☺.
302     </li>
303 </ul>
304
305 <p>
306     In order to represent key presses using the Control, Alt, Meta,
307     or Shift keys, the following prefixes may be used,
308 </p>
309
310 <ol>
311     <li><k name="C-␣" link="false"/>: The control or ctrl key.</li>
312     <li><k name="A-␣" link="false"/>: The alt key.</li>
313     <li><k name="M-␣" link="false"/>: The meta key, windows key, or command key.</li>
314     <li><k name="⌘-␣" link="false"/>: Same as <k name="M-␣" link="false"/>.</li>
315     <li><k name="S-␣" link="false"/>: The shift key.</li>
316 </ol>
317
318 <p>
319     These prefixes can be combined however you see fit.
320 </p>
321
322 <note>
323     Within angle brackets all alphabetic characters are read as lowercase.
324     Uppercase characters can only be specified with the <em>S-</em> modifier.
325 </note>
326
327 <p>
328     The following key sequences are interpreted as described:
329 </p>
330
331 <dl dt="width: 10em;">
332     <dt><k link="false">xc</k></dt>
333     <dd>Press the ‘X’ key followed by the ‘C’ key.</dd>
334
335     <dt><k name="C-x" link="false">c</k></dt>
336     <dd>
337         Press the ‘X’ key while holding the ‘Control’ key, followed
338         by the ‘C’ key.
339     </dd>
340
341     <dt><k name="C-2" link="false"/></dt>
342     <dd>Type ‘2’ while holding the ‘Control’ key.</dd>
343
344     <dt><k name="C-@" link="false"/></dt>
345     <dd>Press the ‘@’ key while holding the ‘Control’ key.</dd>
346
347     <dt><k name="S-Space" link="false"/></dt>
348     <dd>Press the space bar while holding the ‘Shift’ key.</dd>
349
350     <dt><k name="C-A-j" link="false"/></dt>
351     <dd>Press the ‘J’ key while holding both the ‘Control’ and ‘Alt’ keys.</dd>
352
353     <dt><k name="C-A-J" link="false"/></dt>
354     <dd>Exactly the same as above.</dd>
355
356     <dt><k name="C-A-S-j" link="false"/></dt>
357     <dd>Press the ‘J’ key while holding all of ‘Control’, ‘Alt’, and ‘Shift’ keys.</dd>
358 </dl>
359
360 <h3 tag=":map-special-chars">Special characters</h3>
361
362 <item>
363     <tags><![CDATA[<Nop>]]></tags>
364     <strut/>
365     <spec><![CDATA[<Nop>]]></spec>
366     <description>
367         <p>
368             Do nothing. This pseudo-key is useful for disabling a
369             specific builtin mapping. For example,
370             <ex>:map <k name="C-n"/> <k name="Nop"/></ex> will prevent <k name="C-n"/>
371             from doing anything.
372         </p>
373     </description>
374 </item>
375
376 <item>
377     <tags><![CDATA['mapleader' <Leader>]]></tags>
378     <strut/>
379     <spec><![CDATA[<Leader>]]></spec>
380     <description>
381         <p>
382             An arbitrary and meaningless key that some people seem
383             attached to. The <k>\</k> key will, by default, emit
384             this pseudo-key so that it can be used at the start of
385             other mappings. Note, however, that there is nothing
386             special about it and any key can be mapped to emit any
387             other arbitrary pseudo-key in the same way.
388         </p>
389
390         <code><ex>:map , <k name="Leader"/></ex>
391 <ex>:map ; <k name="AwesomestLeaderEver"/></ex>
392
393 <ex>:map <k name="Leader"/>k <key>-js</key> doStuff()</ex>
394 <ex>:map <k name="AwesomestLeaderEver"/>k <key>-js</key> doOtherReallyNiftyStuff()</ex></code>
395
396         <p>
397             Needless to say this behavior is considered childish and
398             discouraged.
399         </p>
400     </description>
401 </item>
402
403 <item>
404     <tags><![CDATA[<Pass>]]></tags>
405     <spec><![CDATA[<Pass>]]></spec>
406     <description short="true">
407         <p>
408             Pass the events consumed by the last executed mapping through to &dactyl.host;.
409         </p>
410     </description>
411 </item>
412
413 <item>
414     <tags><![CDATA[<CR> map_return]]></tags>
415     <strut/>
416     <spec><![CDATA[<CR>]]></spec>
417     <description>
418         <p>
419             Expand to a line terminator in a key mapping. An Ex command in the <a>rhs</a> of a
420             mapping requires a line terminator after it so that it is executed when the
421             mapping is expanded. <k name="CR"/> should be used for this purpose.
422         </p>
423     </description>
424 </item>
425
426 <h3 tag="map-examples">Mapping examples</h3>
427
428 <p>Make <k name="A-n" link="false"/> do the same as <k name="Down" link="false"/> in input <t>modes</t>:</p>
429
430 <code><ex>:map</ex> <em>-b</em> <em>-m</em> input <k name="A-n" link="false"/> <k name="Down" link="false"/></code>
431
432 <p>Toggle the tab line with <k name="A-t" link="false"/>:</p>
433
434 <code><ex>:map</ex> <em>-ex</em> <k name="A-t" link="false"/> <se opt="showtabline" op="!="><str delim="">always</str>,<str delim="">never</str></se></code>
435
436 <p>Make <k name="A-i" link="false"/> toggle image display:</p>
437
438 <code><ex>:map</ex> <k name="A-i" link="false"/> <em>-js</em> &lt;&lt;<em>EOF</em>
439 let (pref = <str>permissions.default.image</str>)
440     prefs.set(pref, prefs.get(pref) == 1 ? 2 : 1);
441 tabs.reload(config.browser.mCurrentTab);
442 <em>EOF</em></code>
443
444
445 <h2 tag="bypassing-&dactyl.name;">Bypassing &dactyl.appName;</h2>
446
447 &dactyl.appName; overrides nearly all &dactyl.host; keys in order to
448 make browsing more pleasant for Vim users. On the occasions when you
449 want to bypass &dactyl.appName;'s key handling and pass keys directly to
450 &dactyl.host; or to a web page, you have several options:
451
452 <item>
453     <tags><![CDATA[<pass-next-key-builtin> <A-b>]]></tags>
454     <spec><![CDATA[<A-b>]]></spec>
455     <description>
456         <p>
457             Process the next key as a builtin mapping, ignoring any user defined
458             mappings and <o>passkeys</o> settings.
459         </p>
460     </description>
461 </item>
462
463 <item>
464     <tags><![CDATA[send-key <pass-next-key> <C-v>]]></tags>
465     <spec><![CDATA[<C-v>]]></spec>
466     <description>
467         <p>
468             Pass the next key press directly to &dactyl.host;.
469         </p>
470     </description>
471 </item>
472
473 <item>
474     <tags><![CDATA[pass-through <pass-all-keys> <C-z>]]></tags>
475     <spec><![CDATA[<C-z>]]></spec>
476     <description>
477         <p>
478             Pass all keys except for <k name="Esc"/> directly to
479             &dactyl.host;. When <k name="Esc"/> is pressed,
480             resume normal key handling. This is especially useful
481             for web sites which make heavy use of key bindings.
482         </p>
483     </description>
484 </item>
485
486 <p>
487     See also <o>passkeys</o> and <o>passunknown</o> for ways to permanently pass
488     all or particular keys under certain conditions.
489 </p>
490
491 <h2 tag="abbreviations">Abbreviations</h2>
492
493 <p>
494     In addition to basic mappings, &dactyl.appName; can also
495     automatically replace whole words after they've been typed.
496     These shortcuts are known as abbreviations, and are most often
497     useful for correcting spelling of commonly mistyped words, as
498     well as shortening the typing of oft-typed but long words or
499     phrases. There are three basic types of abbreviations, defined
500     by the types of characters they contain,
501 </p>
502
503 <ul>
504     <li>‘full-id’ abbreviations consist entirely of keyword characters (e.g., ‘teh’, ‘msoft’).</li>
505     <li>‘end-id’ abbreviations end in keyword character but otherwise contains all non-keyword characters (e.g., ‘'i’).</li>
506     <li>‘non-id’ abbreviations end in a non-keyword character but otherwise contains any non-whitespace character (e.g., ‘def'’).</li>
507     <li>Strings which fit none of the above patterns can not be defined as abbreviations (e.g., ‘a'b’ and ‘a b’).</li>
508 </ul>
509
510 <p>
511     For the purposes of abbreviations, keyword characters include
512     all non-whitespace characters except for single or double
513     quotation marks. Abbreviations are expanded as soon as any
514     non-keyword character, or the key <k name="C-]" mode="c"/>, is typed.
515 </p>
516
517 <item>
518     <tags>:ab :abbreviate</tags>
519     <spec>:ab<oa>breviate</oa> <oa>-group=<a>group</a></oa> <oa>-js</oa> <a>lhs</a> <a>rhs</a></spec>
520     <spec>:ab<oa>breviate</oa> <oa>-group=<a>group</a></oa> <a>lhs</a></spec>
521     <spec>:ab<oa>breviate</oa> <oa>-group=<a>group</a></oa></spec>
522     <description>
523         <p>
524             Abbreviate <a>lhs</a> to <a>rhs</a>. If only <a>lhs</a>
525             is given, list all abbreviations that start with
526             <a>lhs</a>. If no arguments are given, list all
527             abbreviations.
528         </p>
529
530         <p>
531             If the <em>-javascript</em> (short names <em>-js</em>,
532             <em>-j</em>) option is given, <a>lhs</a> is expanded to
533             the value <em>return</em>ed by the JavaScript code
534             <a>rhs</a>. The code is evaluated with the variable
535             <em>editor</em> set to the editable element that the
536             abbreviation is currently being expanded in. The code
537             should <em>not</em> make any changes to the contents of
538             the editor.
539         </p>
540
541         <p>
542             If <a>group</a> is specified then abbreviations are created or
543             listed for the given <t>group</t>.
544         </p>
545     </description>
546 </item>
547
548 <item>
549     <tags>:ca :cabbreviate</tags>
550     <spec>:ca<oa>bbreviate</oa> <a>lhs</a> <a>rhs</a></spec>
551     <spec>:ca<oa>bbreviate</oa> <a>lhs</a></spec>
552     <spec>:ca<oa>bbreviate</oa></spec>
553     <description>
554         <p>
555             Abbreviate a key sequence for Command Line mode. Same as
556             <ex>:ab<oa>breviate</oa></ex>, but for &mode.command-line; mode
557             only.
558         </p>
559     </description>
560 </item>
561
562 <item>
563     <tags>:ia :iabbreviate</tags>
564     <spec>:ia<oa>bbreviate</oa> <a>lhs</a> <a>rhs</a></spec>
565     <spec>:ia<oa>bbreviate</oa> <a>lhs</a></spec>
566     <spec>:ia<oa>bbreviate</oa></spec>
567     <description>
568         <p>
569             Abbreviate a key sequence for Insert mode. Same as
570             <ex>:ab<oa>breviate</oa></ex>, but for Insert mode only.
571         </p>
572     </description>
573 </item>
574
575 <item>
576     <tags>:una :unabbreviate</tags>
577     <spec>:una<oa>bbreviate</oa> <a>lhs</a></spec>
578     <spec>:una<oa>bbreviate</oa>!</spec>
579     <description>
580         <p>Remove an abbreviation. With <oa>!</oa>, remove all abbreviations.</p>
581     </description>
582 </item>
583
584 <item>
585     <tags>:cuna :cunabbreviate</tags>
586     <spec>:cuna<oa>bbreviate</oa> <a>lhs</a></spec>
587     <spec>:cuna<oa>bbreviate</oa>!</spec>
588     <description>
589         <p>
590             Remove abbreviation(s) for Command Line mode. Same as
591             <ex>:una<oa>bbreviate</oa></ex>, but for &mode.command-line; mode
592             only.
593         </p>
594     </description>
595 </item>
596
597 <item>
598     <tags>:iuna :iunabbreviate</tags>
599     <spec>:iuna<oa>bbreviate</oa> <a>lhs</a></spec>
600     <spec>:iuna<oa>bbreviate</oa>!</spec>
601     <description>
602         <p>
603             Remove abbreviation(s) for Insert mode. Same as
604             <ex>:una<oa>bbreviate</oa></ex> but for Insert mode
605             only.
606         </p>
607     </description>
608 </item>
609
610 <h2 tag="user-commands">User-defined commands</h2>
611
612 <p>
613     Defining new commands is perhaps the most straightforward way of
614     repeating commonly used actions. User-defined commands may be
615     entered from the command line or scripts exactly like standard
616     commands, and may similarly accept arguments, options, counts,
617     and <oa>!</oa>s, as well as provide command-line completion.
618     These commands may be defined as either ordinary,
619     macro-interpolated Ex commands, or otherwise as plain
620     JavaScript statements.
621 </p>
622
623 <item>
624     <tags>:com :command</tags>
625     <spec>:com<oa>mand</oa></spec>
626     <description short="true">
627         <p>List all user-defined commands.</p>
628     </description>
629 </item>
630
631 <item>
632     <spec>:com<oa>mand</oa> <oa>cmd</oa></spec>
633     <description>
634         <p>
635             List all user-defined commands that start with <oa>cmd</oa>. Commands
636             are partitioned into <t>groups</t>.
637         </p>
638     </description>
639 </item>
640
641 <item>
642     <spec>:com<oa>mand</oa><oa>!</oa> <oa><a>options</a>…</oa> <a>cmd</a> <a>rep</a></spec>
643     <description>
644         <p>
645             Define a new user command. The name of the command is
646             <a>cmd</a> and its replacement text is <a>rep</a>. If a
647             command with this name already exists, an error is
648             reported unless <oa>!</oa> is specified, in which case
649             the command is redefined. Unlike Vim, the command may
650             start with a lowercase letter. <a>cmd</a> may also be multiple
651             alternative command names separated by commas.
652         </p>
653
654         <p>
655             The new command is usually defined by a string to be
656             executed as an Ex command. In this case, before
657             execution, strings of the form
658             <hl key="HelpKey">&lt;<a>var</a>></hl> are interpolated
659             as described below, in order to insert arguments,
660             options, and the like. If the <em>-javascript</em> (short
661             name <em>-js</em>) flag is present, the command is
662             executed as JavaScript, and the arguments are present as
663             variables in its scope instead, and no interpolation is
664             performed.
665         </p>
666
667         <p>
668             The command's behavior can be altered by providing
669             options when the command is defined.
670         </p>
671
672         <h3 tag=":command-group">Grouping</h3>
673
674         <p>
675             The <em>-group</em> flag (short name: <em>-g</em>) can be used to
676             assign this command to a specific <t>group</t>.  When listing
677             commands this limits the output to the specified group.
678         </p>
679
680         <h3 tag="E175 E176 :command-nargs">Argument handling</h3>
681
682         <p>
683             By default, user commands accept no arguments. This can be changed by specifying
684             the <em>-nargs</em> option.
685         </p>
686
687         <p>The valid values are:</p>
688
689         <dl>
690             <dt>-nargs=0</dt><dd>No arguments are allowed (default)</dd>
691             <dt>-nargs=1</dt><dd>One argument is allowed</dd>
692             <dt>-nargs=*</dt><dd>Zero or more arguments are allowed</dd>
693             <dt>-nargs=?</dt><dd>Zero or one argument is allowed</dd>
694             <dt>-nargs=+</dt><dd>One or more arguments are allowed</dd>
695         </dl>
696
697         <h3 tag="E180 E181 :command-complete">Argument completion</h3>
698
699         <p>
700             Completion for arguments to user-defined commands is not available by default.
701             Completion can be enabled by specifying one of the following arguments to the
702             <em>-complete</em> option when defining the command.
703         </p>
704
705         <dl tag=":command-complete-arg-list"/>
706
707         <h3 tag="E467 E468 :command-completion-custom">Custom completion</h3>
708
709         <p>
710             Custom completion can be provided by specifying the
711             <str>custom,<a>thing</a></str> argument to <em>-complete</em>. If
712             <a>thing</a> evaluates to a function (i.e., it is a variable holding
713             a function value, or a string containing the definition itself), it
714             is called with two arguments: a completion context, and an object
715             describing the command's arguments. It should set the context's
716             <tt>completions</tt> property to the list of completion results.
717             Other influential properties include <tt>title</tt>, <tt>sort</tt>,
718             <tt>anchored</tt>, and <tt>filters</tt>, which are documented in the
719             <link topic="resource://dactyl/completion.jsm"
720                 line="17" dactyl:command="buffer.viewSource">source code</link>.
721         </p>
722
723         <p>
724             <em>completions</em> is a two-dimensional array of the form:
725             <tt>[[val1, description1], [val2, description2], …]</tt>
726         </p>
727
728         <p>
729             Otherwise <a>thing</a> should evaluate to an array of the same form
730             as the <tt>completions</tt> property of the context object.
731         </p>
732
733         <p>
734             Example:
735             <code><ex>:command foo -nargs=? -complete custom,<str delim="'">
736     \ function (context) context.completions = [["val1", "description1"], ["val2", "description2"]]</str>
737     \ <ex>:echo</ex> <str>Useless </str> + <em>&lt;q-args></em></ex>
738
739 <ex>:command foo -nargs=?
740     \ -complete custom,<str delim="'">[["val1", "description1"], ["val2", "description2"]]</str>
741     \ <ex>:echo</ex> <str>Same as above but simpler </str> + <em>&lt;q-args></em></ex></code>
742         </p>
743
744         <h3 tag="E177 E178 :command-count">Count handling</h3>
745
746         <p>
747             By default, user commands do not accept a count. Use the <em>-count</em> option if
748             you'd like to have a count passed to your user command. This will then be
749             available for expansion as &lt;count> in the replacement.
750         </p>
751
752         <h3 tag=":command-bang">Special cases</h3>
753
754         <p>
755             By default, a user command does not have a special version, i.e. a version
756             executed with the ! modifier. Providing the <em>-bang</em> option will enable this
757             and &lt;bang> will be available in the replacement.
758         </p>
759
760         <h3 tag=":command-description">Command description</h3>
761
762         <p>
763             The command's description text can be set with <em>-description</em>. Otherwise it will
764             default to "User-defined command".
765         </p>
766
767         <h3 tag=":command-replacement-text">Replacement text</h3>
768
769         <p>
770             The replacement text <a>rep</a> is scanned for <t>macro-string</t>s and these are
771             replaced with values from the user-entered command line. The resulting string
772             is then executed as an Ex command.
773         </p>
774
775         <p>
776             In addition to the standard parameters listed in
777             <t>macro-string</t>, the following parameters are available:
778         </p>
779
780         <dl>
781             <dt>&lt;args></dt> <dd>The command arguments exactly as supplied</dd>
782             <dt>&lt;count></dt><dd>Any supplied count, e.g. 5</dd>
783             <dt>&lt;bang></dt> <dd>! if the command was executed with the ! modifier</dd>
784         </dl>
785     </description>
786 </item>
787
788 <item>
789     <tags>:delc :delcommand</tags>
790     <spec>:delc<oa>ommand</oa> <a>cmd</a></spec>
791     <spec>:delc<oa>ommand</oa>!</spec>
792     <description>
793         <p>Delete the user-defined command <a>cmd</a>. With <oa>!</oa>, delete
794             all user commands.</p>
795     </description>
796 </item>
797
798 <h3 tag="command-examples">Command examples</h3>
799
800 <p>A command to search via DuckDuckGo:</p>
801
802 <code><ex>:command</ex> <em>-nargs</em>=* <str delim="">ddg</str> open ddg &lt;args></code>
803
804 <p>
805     A command to search for contents of the current selection using a
806     tab-completed search engine in the current or a new tab (depending on how
807     much you bang on the keyboard):
808 </p>
809
810 <code><ex>:com!</ex> <str delim="">search-selection</str>,<str delim="">ss</str> <em>-bang</em> <em>-nargs</em>=? <em>-complete</em> search
811         \ <em>-js</em> commands.execute((bang ? <str>open </str> : <str>tabopen </str>)
812         \ + args + <str> </str> + buffer.currentWord)</code>
813
814 </document>
815
816 <!-- vim:se sts=4 sw=4 et: -->