Loading ...
Sorry, an error occurred while loading the content.

Re: problem mapping

Expand Messages
  • Tony Mechelynck
    ... - 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., â
    Message 1 of 4 , Sep 2, 2009
    • 0 Attachment
      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
      -~----------~----~----~----~------~----~------~--~---
    • CHEN Cheng
      ... Hi Tony, thanks for your response. ... Note: the listed terminals are configured into two modes, escape meta mode and 8bit meta mode, respectively. For
      Message 2 of 4 , Sep 3, 2009
      • 0 Attachment
        On Thu, Sep 03, 2009 at 04:28:54AM +0200, Tony Mechelynck wrote:
        >
        > 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
        >

        Hi Tony, thanks for your response.

        > - 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
        >

        I tried 'bit' but failed. Please see the test record I made below:

        |-------------------+------------+-----+-----+-----------+-----+-----|
        | terminal / config | SendEscape | | | 8bit_meta | | |
        |-------------------+------------+-----+-----+-----------+-----+-----|
        | vim mapping | <M-b> | ^]b | cat | <M-b> | ^]b | cat |
        | and cat test | | | | | | |
        |===================+============+=====+=====+===========+=====+=====|
        | xterm $TERM=xterm | â | ok | ^]b | ok | â | â |
        |-------------------+------------+-----+-----+-----------+-----+-----|
        | gnome-terminal | | | | no 8bit |
        | $TERM=xterm | â | ok | ^]b | mode |
        |-------------------+------------+-----+-----+-----------+-----+-----|
        | Linux virtual | | | | | | |
        | terminal (VT) | â | ok | ^]b | â | â | â |
        |-------------------+------------+-----+-----+-----------+-----+-----|
        | putty | | | | |
        | $TERM=xterm | â | ok | ^]b | no test |
        |-------------------+------------+-----+-----+-----------+-----+-----|
        Note: the listed terminals are configured into two modes, escape meta
        mode and 8bit meta mode, respectively. For each mode, the output
        after pressing Alt-b is shown in three settings:
        <M-b> :set <M-b>=^]b before :imap <M-b> ok
        ^]b :imap ^]b YYYY directly
        cat not in vim, but in stdin, which is provided by
        executing 'cat' in the shell
        Note: the tests are done in `LANG=en_US.UTF-8 vim`.

        As you see, in 8bit mode (linux console), "â" is what I always get.

        > 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.
        >

        Aha, your experiment made me blame the difference between your box
        and mine. Suddenly, an idea came out, which asked me to check $LANG.

        I did:
        $ LANG=C vim
        Guess what? I reproduced your experiment. I also see YYYY!!!

        But, when I:
        $ echo $LANG
        en_US.UTF-8
        $ vim
        Oops, "â" came out as before.

        So, for vim, the problem might be utf8 support conflicting with
        meta key handling.

        Since I use the Chinese language, I can't set encoding to latin1, which
        turns Chinese characters into a mess.

        I think I'd better live with escape meta key mode, because gnome-terminal
        supports Chinese well, but it doesn't support 8bit meta key mode.


        Best regards,
        Cheng


        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Tony Mechelynck
        On 03/09/09 14:59, CHEN Cheng wrote: [...] ... Current language:
        Message 3 of 4 , Sep 3, 2009
        • 0 Attachment
          On 03/09/09 14:59, CHEN Cheng wrote:
          [...]
          > Aha, your experiment made me blame the difference between your box
          > and mine. Suddenly, an idea came out, which asked me to check $LANG.
          >
          > I did:
          > $ LANG=C vim
          > Guess what? I reproduced your experiment. I also see YYYY!!!
          >
          > But, when I:
          > $ echo $LANG
          > en_US.UTF-8
          > $ vim
          > Oops, "â" came out as before.
          >
          > So, for vim, the problem might be utf8 support conflicting with
          > meta key handling.
          >
          > Since I use the Chinese language, I can't set encoding to latin1, which
          > turns Chinese characters into a mess.
          >
          > I think I'd better live with escape meta key mode, because gnome-terminal
          > supports Chinese well, but it doesn't support 8bit meta key mode.
          >
          >
          > Best regards,
          > Cheng

          :lang " in gvim
          Current language:
          "LC_CTYPE=en_US.UTF-8;LC_NUMERIC=en_US.UTF-8;LC_TIME=en_GB;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=C;LC_PAPER=en_GB;LC_NAME=en_US.UTF-8;LC_ADDRESS=en_US.UTF-8;LC_TELEPHONE=en_US.UTF-8;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=en_US.UTF-8"

          :lang " in Console Vim in Linux console
          Current language:
          "LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_GB;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=C;LC_PAPER=en_GB;LC_NAME=en_US.UTF-8;LC_ADDRESS=en_US.UTF-8;LC_TELEPHONE=en_US.UTF-8;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=en_US.UTF-8"

          :lang " in Console Vim in KDE3 konsole
          Current language:
          "LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_GB;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=C;LC_PAPER=en_GB;LC_NAME=en_US.UTF-8;LC_ADDRESS=en_US.UTF-8;LC_TELEPHONE=en_US.UTF-8;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=en_US.UTF-8"

          also, 'encoding' is set to utf-8 in both. 'termencoding' is empty in the
          linux console (meaning "use 'encoding'") and utf-8 (set forcibly at GUI
          startup) in gvim with GTK+2 GUI.

          The important one should be LC_CTYPE, IIUC. In gvim, Alt-b opens the
          Buffers menu regardless of mappings (which may be due to 'winaltkeys'
          set to menu). In Console Vim in konsole, with esc-meta, the mapping
          doesn't word and Alt-b is seen as Esc + b (leave Insert mode and go back
          one word). In Console mode in /dev/tty3, with bit-meta, the mapping
          doesn't work (I get â).

          Strange that it worked yesterday but not today; but I'm not gonna keep
          that mapping because a-circumflex is (in French) something I need to be
          able to type: hence no alt-b mappings for me. If I need some mapping
          I'll use an Fn key (or Shift+Fn).


          Best regards,
          Tony.
          --
          Living on Earth may be expensive, but it includes an annual free trip
          around the Sun.

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        Your message has been successfully submitted and would be delivered to recipients shortly.