2017-11-02 03:03:24 +01:00
|
|
|
= Mapping
|
2017-03-07 15:39:40 +01:00
|
|
|
|
2017-11-02 03:03:24 +01:00
|
|
|
== Description
|
2017-03-07 15:39:40 +01:00
|
|
|
|
|
|
|
Creating and removing shortcuts boils down to the following commands,
|
|
|
|
respectively:
|
|
|
|
|
|
|
|
---------------------------------------
|
2018-04-03 13:33:30 +02:00
|
|
|
map [switches] <scope> <mode> <key> <keys>
|
2017-03-07 15:39:40 +01:00
|
|
|
unmap <scope> <mode> <key> [<expected>]
|
|
|
|
---------------------------------------
|
|
|
|
|
|
|
|
The *map* command makes *key* behave as if the *keys* sequence was typed.
|
|
|
|
|
|
|
|
*mode* dictates in what context the mapping will be available:
|
|
|
|
|
2017-11-02 10:37:39 +01:00
|
|
|
*insert*::
|
|
|
|
insert mode
|
2018-04-03 13:33:30 +02:00
|
|
|
|
2017-11-02 10:37:39 +01:00
|
|
|
*normal*::
|
|
|
|
normal mode
|
2018-04-03 13:33:30 +02:00
|
|
|
|
2017-11-02 10:37:39 +01:00
|
|
|
*prompt*::
|
|
|
|
prompts, such as when entering a command through *:*, or a regex through */*
|
2018-04-03 13:33:30 +02:00
|
|
|
|
2017-11-02 10:37:39 +01:00
|
|
|
*menu*::
|
|
|
|
mode entered when a menu is displayed with the 'menu' command
|
2018-04-03 13:33:30 +02:00
|
|
|
|
2017-11-02 10:37:39 +01:00
|
|
|
*user*::
|
2023-06-01 19:25:12 +02:00
|
|
|
mode entered when the user prefix is hit (default: '<space>')
|
2018-04-03 13:33:30 +02:00
|
|
|
|
2017-11-02 10:37:39 +01:00
|
|
|
*goto*::
|
|
|
|
mode entered when the goto key is hit (default: 'g')
|
2018-04-03 13:33:30 +02:00
|
|
|
|
2017-11-02 10:37:39 +01:00
|
|
|
*view*::
|
|
|
|
mode entered when the view key is hit (default: 'v')
|
2018-04-03 13:33:30 +02:00
|
|
|
|
2017-11-02 10:37:39 +01:00
|
|
|
*object*::
|
|
|
|
mode entered when an object selection is triggered (e.g. '<a-i>')
|
2017-03-07 15:39:40 +01:00
|
|
|
|
|
|
|
The context of execution of the above modes is always the current one at the
|
|
|
|
time of execution of the mapping, except for *user* mode (always executed
|
2018-02-23 14:31:28 +01:00
|
|
|
in a 'normal' context). Refer to <<modes#,`:doc modes`>> for more details.
|
2017-03-07 15:39:40 +01:00
|
|
|
|
|
|
|
An optional *-docstring* switch followed by a string can be used
|
|
|
|
to describe what the mapping does. This docstring will be used
|
|
|
|
in autoinfo boxes.
|
|
|
|
|
|
|
|
The *unmap* command removes a mapping of *key* in the given *scope* and
|
|
|
|
*mode*. If *expected* is specified, the mapping is removed only if it is
|
|
|
|
set to the same sequence of keys passed using the *expected* argument.
|
|
|
|
|
|
|
|
For more information about the values of the *scope* parameter, refer to
|
2017-11-06 10:08:59 +01:00
|
|
|
<<scopes#,`:doc scopes`>>.
|
2017-09-18 04:59:41 +02:00
|
|
|
|
2018-09-25 10:42:07 +02:00
|
|
|
== Mapping commands
|
|
|
|
|
|
|
|
It's common to use a normal-mode or user-mode mapping to trigger a command,
|
|
|
|
like this:
|
|
|
|
|
|
|
|
----
|
2022-07-31 11:19:48 +02:00
|
|
|
map global user n :make-next-error<ret>
|
2018-09-25 10:42:07 +02:00
|
|
|
----
|
|
|
|
|
|
|
|
If you make a normal-mode mapping, you can prefix it with a count or a register
|
|
|
|
name like any other normal-mode key. You can forward this information to the
|
|
|
|
command you invoke with the `%val{count}` and `%val{register}` expansions
|
|
|
|
(See <<expansions#`:doc expansions`>>). For example:
|
|
|
|
|
|
|
|
----
|
2022-07-30 22:28:02 +02:00
|
|
|
map global normal = ':echo Got count %val{count} and reg %val{register}<ret>'
|
2018-09-25 10:42:07 +02:00
|
|
|
----
|
|
|
|
|
2017-11-02 03:03:24 +01:00
|
|
|
== Mappable keys
|
2017-09-18 04:59:41 +02:00
|
|
|
|
2023-10-08 04:04:15 +02:00
|
|
|
See <<keys#,`:doc keys`>> to learn what each key does in each mode. The keys on
|
|
|
|
the right-hand side of the mapping are not affected by other mappings, they
|
|
|
|
always perform their original function.
|
2018-02-23 14:31:28 +01:00
|
|
|
|
2017-09-18 04:59:41 +02:00
|
|
|
For *key* and *keys* in the *map* command, the following key names can
|
|
|
|
be used:
|
|
|
|
|
|
|
|
*x*, *<x>*::
|
2017-11-02 10:37:39 +01:00
|
|
|
Most keys, especially alphabetic keys, represent themselves.
|
|
|
|
Keys can also be wrapped in angle-brackets for consistency
|
|
|
|
with the non-alphabetic keys below.
|
2017-09-18 04:59:41 +02:00
|
|
|
|
|
|
|
*<c-x>*::
|
2017-11-02 10:37:39 +01:00
|
|
|
Holding down Control while pressing the *x* key.
|
2017-09-18 04:59:41 +02:00
|
|
|
|
|
|
|
*<a-x>*::
|
2017-11-02 10:37:39 +01:00
|
|
|
Holding down Alt while pressing the *x* key.
|
2017-09-18 04:59:41 +02:00
|
|
|
|
2018-03-15 13:02:27 +01:00
|
|
|
*<s-x>*, *X*, *<X>*, *<s-X>*::
|
|
|
|
Holding down Shift while pressing the *x* key.
|
|
|
|
*<s-x>*, *<s-X>* and *<X>* are treated as the same key. The *s-* modifier
|
|
|
|
only works with ASCII letters and cannot be used with other printable keys
|
|
|
|
(non-ASCII letters, digits, punctuation) because their shift behaviour
|
|
|
|
depends on your keyboard layout. The *s-* modifier _can_ be used with
|
|
|
|
special keys like *<up>* and *<tab>*.
|
|
|
|
|
2017-11-06 10:08:59 +01:00
|
|
|
*<c-a-x>*::
|
|
|
|
Holding down Control and Alt while pressing the *x* key.
|
|
|
|
|
2017-09-18 04:59:41 +02:00
|
|
|
*<lt>*, *<gt>*::
|
2017-11-02 10:37:39 +01:00
|
|
|
The *<* and *>* characters.
|
2017-09-18 04:59:41 +02:00
|
|
|
|
|
|
|
*<plus>*, *<minus>*::
|
2018-04-03 13:33:30 +02:00
|
|
|
The *+* and *-* characters.
|
2017-09-18 04:59:41 +02:00
|
|
|
|
|
|
|
*<ret>*::
|
2017-11-02 10:37:39 +01:00
|
|
|
The Return or Enter key.
|
2017-09-18 04:59:41 +02:00
|
|
|
|
|
|
|
*<space>*::
|
2017-11-02 10:37:39 +01:00
|
|
|
The space bar.
|
2017-09-18 04:59:41 +02:00
|
|
|
|
|
|
|
*<tab>*::
|
2017-11-02 10:37:39 +01:00
|
|
|
The Tab key.
|
2017-09-18 04:59:41 +02:00
|
|
|
|
|
|
|
*<backspace>*::
|
2017-11-02 10:37:39 +01:00
|
|
|
The Backspace (delete to the left) key.
|
2017-09-18 04:59:41 +02:00
|
|
|
|
|
|
|
*<del>*::
|
2017-11-02 10:37:39 +01:00
|
|
|
The Delete (to the right) key.
|
2017-09-18 04:59:41 +02:00
|
|
|
|
|
|
|
*<esc>*::
|
2017-11-02 10:37:39 +01:00
|
|
|
The Escape key.
|
2017-09-18 04:59:41 +02:00
|
|
|
|
2017-11-06 10:08:59 +01:00
|
|
|
*<up>*, *<down>*, *<left>*, *<right>*::
|
|
|
|
*<pageup>*, *<pagedown>*, *<home>*, *<end>*::
|
2017-11-02 10:37:39 +01:00
|
|
|
The usual cursor-movement keys.
|
2017-09-18 04:59:41 +02:00
|
|
|
|
2019-07-07 18:38:46 +02:00
|
|
|
*<ins>*::
|
|
|
|
The Insert key.
|
|
|
|
|
2019-07-07 18:44:14 +02:00
|
|
|
*<F1>*, *<F2>*, ...*<F12>*::
|
2017-11-02 10:37:39 +01:00
|
|
|
Function keys.
|
2018-03-15 13:02:27 +01:00
|
|
|
|
2020-12-15 15:13:02 +01:00
|
|
|
*<semicolon>*, *<percent>*::
|
|
|
|
The *;* and *%* characters, these keys allow reducing the amount of
|
|
|
|
backslash escaping in scripts (for example, `exec \%` becomes `exec
|
|
|
|
<percent>`)
|
|
|
|
|
2018-03-15 13:02:27 +01:00
|
|
|
NOTE: Although Kakoune allows many key combinations to be mapped, not every
|
|
|
|
possible combination can be triggered. For example, due to limitations in
|
|
|
|
the way terminals handle control characters, mappings like *<c-s-a>* are
|
|
|
|
unlikely to work in Kakoune's terminal UI.
|
2019-09-15 11:40:38 +02:00
|
|
|
|
2023-05-21 12:14:56 +02:00
|
|
|
Some keys, like `<c-c>` and `<c-g>`, cannot be remapped because they are
|
|
|
|
used to cancel operations. See <<keys#cancelling-operations,`:doc keys cancelling-operations`>>.
|
|
|
|
|
2019-09-15 11:40:38 +02:00
|
|
|
== Default mappings
|
|
|
|
|
|
|
|
Some mappings exist by default in the global scope:
|
|
|
|
|
|
|
|
In normal mode:
|
|
|
|
|
|
|
|
* `<left>` maps to `h`
|
|
|
|
* `<right>` maps to `l`
|
|
|
|
* `<up>` maps to `k`
|
|
|
|
* `<down>` maps to `j`
|
|
|
|
* `<home>` maps to `<a-h>`
|
|
|
|
* `<end>` maps to `<a-l>`
|
|
|
|
|
|
|
|
Shift version of those mappings exist as well
|
|
|
|
(for example `<s-left>` maps to `H`).
|