2016-01-09 0:53 GMT+03:00 Christian Brabandt <[email protected]>:

> Hi,
> I think I found an inconsistency.
>
> #v+
> vim -u NONE -N
> :let @a='foobar'
> :fu AB()
>     return "<c-r>a"
> :endfu
> :fu CD()
>      return "\<c-r>a"
> :endfu
> :imap <expr> ab '<c-r>a'
> :imap <expr> cd AB()
> :imap <expr> ef CD()
> #v-
> Now enter insert mode:
>
> 1) Inserting ab results in:
> foobar
> 2) Inserting cd results in:
> <c-r>a
> 3) Inserting ef results in:
> foobar
>
> That is unexpected. I think the first case, it should also insert
> '<c-r>a' Since according to the documentation (:h expr-quote) keys need
> to be returned like "\<key>" in a double quoted string.
>
> How would one return the literal string "<c-r>a" in the first case?
> Is this a bug or did I miss anything?
>

​You miss how maps are parsed. When filling mappings table (i.e. at the
time :*map commands are parsed themselves) rhs always has special keys
translated, regardless whether it is <expr> or not.​ And only then, when
you type something, this is treated as expression. This way allows
`:inoremap <expr> foo <SID>Func()` to work: `<SID>` must be translated
before mapping is run because mapping is run in the currently effective
script context and not in the context of the script it was defined in
(unlike :command does).

To have literal string you need to escape `<` just as you will do in case
of other mappings: `'<LT>c-r>a'`. Or you may abstract this away in a
function or global variable.



>
> Best,
> Christian
> --
> Alles Gute kommt nach oben.
>
> --
> --
> You received this message from the "vim_dev" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups
> "vim_dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui