= Mapping == Description Creating and removing shortcuts boils down to the following commands, respectively: --------------------------------------- map [switches] unmap [] --------------------------------------- The *map* command makes *key* behave as if the *keys* sequence was typed. *mode* dictates in what context the mapping will be available: *insert*:: insert mode *normal*:: normal mode *prompt*:: prompts, such as when entering a command through *:*, or a regex through */* *menu*:: mode entered when a menu is displayed with the 'menu' command *user*:: mode entered when the user prefix is hit (default: ',') *goto*:: mode entered when the goto key is hit (default: 'g') *view*:: mode entered when the view key is hit (default: 'v') *object*:: mode entered when an object selection is triggered (e.g. '') 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 in a 'normal' context). Refer to <> for more details. 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 <>. == Mapping commands It's common to use a normal-mode or user-mode mapping to trigger a command, like this: ---- map global user n :make-next-error ---- 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 <>). For example: ---- map global normal = ':echo Got count %val{count} and reg %val{register}' ---- == Mappable keys See <> to discover the list of default bindings. For *key* and *keys* in the *map* command, the following key names can be used: *x*, **:: Most keys, especially alphabetic keys, represent themselves. Keys can also be wrapped in angle-brackets for consistency with the non-alphabetic keys below. **:: Holding down Control while pressing the *x* key. **:: Holding down Alt while pressing the *x* key. **, *X*, **, **:: Holding down Shift while pressing the *x* key. **, ** and ** 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 ** and **. **:: Holding down Control and Alt while pressing the *x* key. **, **:: The *<* and *>* characters. **, **:: The *+* and *-* characters. **:: The Return or Enter key. **:: The space bar. **:: The Tab key. **:: The Backspace (delete to the left) key. **:: The Delete (to the right) key. **:: The Escape key. **, **, **, **:: **, **, **, **:: The usual cursor-movement keys. **:: The Insert key. **, **, ...**:: Function keys. **, **:: The *;* and *%* characters, these keys allow reducing the amount of backslash escaping in scripts (for example, `exec \%` becomes `exec `) 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 ** are unlikely to work in Kakoune's terminal UI. Some keys, like `` and ``, cannot be remapped because they are used to cancel operations. See <>. == Default mappings Some mappings exist by default in the global scope: In normal mode: * `` maps to `h` * `` maps to `l` * `` maps to `k` * `` maps to `j` * `` maps to `` * `` maps to `` Shift version of those mappings exist as well (for example `` maps to `H`).