From 957cf67d50516ba98716f59c9e1cb6412ec1535d Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Thu, 12 Nov 2020 14:21:06 +0100 Subject: patch 8.2.1978: making a mapping work in all modes is complicated Problem: Making a mapping work in all modes is complicated. Solution: Add the special key. (Yegappan Lakshmanan, closes #7282, closes 4784, based on patch by Bjorn Linse) --- runtime/doc/map.txt | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'runtime/doc/map.txt') diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt index 276ab50509..83a5428ce6 100644 --- a/runtime/doc/map.txt +++ b/runtime/doc/map.txt @@ -1,4 +1,4 @@ -*map.txt* For Vim version 8.2. Last change: 2020 Oct 07 +*map.txt* For Vim version 8.2. Last change: 2020 Nov 12 VIM REFERENCE MANUAL by Bram Moolenaar @@ -271,7 +271,7 @@ For this reason the following is blocked: - The |:normal| command. - Moving the cursor is allowed, but it is restored afterwards. If you want the mapping to do any of these let the returned characters do -that. +that, or use a || mapping instead. You can use getchar(), it consumes typeahead if there is any. E.g., if you have these mappings: > @@ -303,6 +303,40 @@ empty string, so that nothing is inserted. Note that using 0x80 as a single byte before other text does not work, it will be seen as a special key. + ** *:map-cmd* +The special text begins a "command mapping", it executes the command +directly without changing modes. Where you might use ":..." in the +{rhs} of a mapping, you can instead use "...". +Example: > + noremap x echo mode(1) +< +This is more flexible than `:` in Visual and Operator-pending mode, or +`:` in Insert mode, because the commands are executed directly in the +current mode, instead of always going to Normal mode. Visual mode is +preserved, so tricks with |gv| are not needed. Commands can be invoked +directly in Command-line mode (which would otherwise require timer hacks). +Example of using halfway Insert mode: > + nnoremap aText echo mode(1) Added + +Unlike mappings, there are no special restrictions on the +command: it is executed as if an (unrestricted) |autocmd| was invoked. + +Note: +- Because avoids mode-changes it does not trigger |CmdlineEnter| and + |CmdlineLeave| events, because no user interaction is expected. +- For the same reason, |keycodes| like are interpreted as plain, + unmapped keys. +- In Select mode, |:map| and |:vmap| command mappings are executed in + Visual mode. Use |:smap| to handle Select mode differently. + + *E1135* *E1136* + commands must terminate, that is, they must be followed by in the +{rhs} of the mapping definition. |Command-line| mode is never entered. + + *E1137* + commands can have only normal characters and cannot contain special +characters like function keys. + 1.3 MAPPING AND MODES *:map-modes* *mapmode-nvo* *mapmode-n* *mapmode-v* *mapmode-o* -- cgit v1.2.3