mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-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 <Cmd> special key. (Yegappan Lakshmanan, closes vim/vim#7282,
closes 4784, based on patch by Bjorn Linse)
957cf67d50
Change docs to match Vim if it's wording is better.
Change error numbers to match Vim.
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -290,7 +290,7 @@ Therefore the following is blocked for <expr> mappings:
|
||||
- Moving the cursor is allowed, but it is restored afterwards.
|
||||
- If the cmdline is changed, the old text and cursor position are restored.
|
||||
If you want the mapping to do any of these let the returned characters do
|
||||
that. (Or use a |<Cmd>| mapping instead.)
|
||||
that, or use a |<Cmd>| mapping instead.
|
||||
|
||||
You can use getchar(), it consumes typeahead if there is any. E.g., if you
|
||||
have these mappings: >
|
||||
@@ -324,19 +324,21 @@ be seen as a special key.
|
||||
|
||||
*<Cmd>* *:map-cmd*
|
||||
The <Cmd> pseudokey begins a "command mapping", which executes the command
|
||||
directly (without changing modes). Where you might use ":...<CR>" in the
|
||||
directly without changing modes. Where you might use ":...<CR>" in the
|
||||
{rhs} of a mapping, you can instead use "<Cmd>...<CR>".
|
||||
Example: >
|
||||
noremap x <Cmd>echo mode(1)<cr>
|
||||
noremap x <Cmd>echo mode(1)<CR>
|
||||
<
|
||||
This is more flexible than `:<C-U>` in visual and operator-pending mode, or
|
||||
`<C-O>:` in insert-mode, because the commands are executed directly in the
|
||||
current mode (instead of always going to normal-mode). Visual-mode is
|
||||
This is more flexible than `:<C-U>` in Visual and Operator-pending mode, or
|
||||
`<C-O>:` 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 cmdline-mode (which would otherwise require timer hacks).
|
||||
directly in Command-line mode (which would otherwise require timer hacks).
|
||||
Example of using <Cmd> halfway Insert mode: >
|
||||
nnoremap <F3> aText <Cmd>echo mode(1)<CR> Added<Esc>
|
||||
|
||||
Unlike <expr> mappings, there are no special restrictions on the <Cmd>
|
||||
command: it is executed as if an (unrestricted) |autocommand| was invoked
|
||||
command: it is executed as if an (unrestricted) |autocmd| was invoked
|
||||
or an async event event was processed.
|
||||
|
||||
Note:
|
||||
@@ -350,7 +352,7 @@ Note:
|
||||
- In Visual mode you can use `line('v')` and `col('v')` to get one end of the
|
||||
Visual area, the cursor is at the other end.
|
||||
|
||||
*E5520*
|
||||
*E1135* *E1136*
|
||||
<Cmd> commands must terminate, that is, they must be followed by <CR> in the
|
||||
{rhs} of the mapping definition. |Command-line| mode is never entered.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user