Wednesday, September 2, 2009

Re: problem mapping

On 25/08/09 19:40, CHEN Cheng wrote:
>
> Hi folks,
>
> When I map<M-b>, a character "â" shows up, instead of the expected rhs.
> But, if I map ^]b directly, everything works, which is very interesting.
>
> What I did:
> 1. vim
> 2. :set<M-b>=^[b
> 3. :imap<M-b> YYYY
> 4. i, goto insert mode
> 5. press<M-b>, nothing happened on the screen
> 6. press<M-b>, still nothing
> 7. press<M-b>, character "â" was inserted
>
> What I expected:
> A sequence of YYYY was inserted
>
> Workaround:
> 1. vim
> 2. :imap ^[b YYYY
> 3. i, goto insert mode
> 4. press<M-b>, a sequence of YYYY was inserted
>
> Reproduce: everytime
> 1. Vim 7.1.242
> 1.1 set esckeys
> 2. Linux, Fedora Core 7
> 2.1 Virtual Terminal, TERM=linux
> 2.2 setmetamode esc
>
> It seems vim treats assigned<M-b> and ^]b differently, but actually
> <M-b> has the value of ^]b. Is it a contradiction?
>
> Note: ^]b is a sequence of escape and letter "b".
>
>
> Thanks in advance,
> Cheng

- See ":help :map-alt-keys"

- Since, to Vim, [key + 0x80] is equivalent to [Meta+key], Alt-b (where
b is 0x62) will be stored in mappings as 0xE2, i.e., â (small Latin a
with circumflex).

- I don't think 'esckeys' applies to <M-...> (but I could be wrong).

- IIUC, your "setmetamode esc" is the culprit. Try

setmetamode bit

instead. Vim "ought" to recognise this with no problem; however, when I
do that on a Linux terminal here, Vim requires pressing the key between
three and five times (i.e., press Alt, hit aaa, release Alt; or press
Alt, hit zzzzz, release Alt) before it notices that I've done anything.

With "setmetamode esc", Vim sees the Esc+something immediately, but as
Esc followed by something else, not as an Alt-key combo. In Insert mode
I get nothing, or maybe a beep, etc., depending on which key was used
with Alt; and if prefixed by Ctrl-V I see ^[a ^[b ^[c etc. instead of á
â ã (a-acute a-circumflex a-tilde) which are correct for Alt-a Alt-b
Alt-c respectively.

I don't know why you saw â and not YYYY when hitting Alt-b repeatedly
after doing

:set <M-b>=^[b
:imap <M-b> YYYY

where ^[ is entered by hitting Ctrl-V followed by Esc, or (alternately)
^[b by hitting Ctrl-V followed by Alt-b. When I do it (in that order,
and when Vim was started in a linux console on /dev/tty3 just after
using "setmetamode esc"), I see YYYY. (I'm using a "Huge" Vim 7.2.245 on
openSUSE Linux 11.1.) For me (where it works) it wouldn't be practical
since it would mean using twice as many "set" statements as there are
"printable" keys on my keyboard -- one for each unshifted meta+key and
one for each shifted meta+key.


Best regards,
Tony.
--
A hypothetical paradox:
What would happen in a battle between an Enterprise security
team, who always get killed soon after appearing, and a squad of
Imperial Stormtroopers, who can't hit the broad side of a planet?
-- Tom Galloway

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

No comments: