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

getchar() / nr2char() with non-default 'keymap'

Expand Messages
  • Justin M. Keyes
    Hi, I am using getchar() in a plugin to get input from the user. But getchar() returns the same keycode no matter what keymap is activated. ... With this
    Message 1 of 3 , Jan 5, 2014
    • 0 Attachment
      Hi,

      I am using getchar() in a plugin to get input from the user. But
      getchar() returns the same keycode no matter what keymap is activated.
      So for example:

      :set keymap=bulgarian-phonetic

      With this keymap, in insert-mode, typing "b" on a US keyboard inputs
      "б". But typing "b" in the getchar() prompt always returns 98, and
      nr2char(98) always returns "b" regardless of the keymap.

      Is there some other function instead of nr2char() that gets the
      keymapped character from a keycode?

      Vim 7.4.35

      Thanks!

      Justin M. Keyes

      --
      --
      You received this message from the "vim_use" 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_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Andy Wokula
      ... You can do the lmap-translation yourself func! LmapArg(chr) let chrtrans = maparg(a:chr, l ) return chrtrans== ? a:chr : chrtrans endfunc With enabled
      Message 2 of 3 , Jan 6, 2014
      • 0 Attachment
        Am 05.01.2014 22:28, schrieb Justin M. Keyes:
        > Hi,
        >
        > I am using getchar() in a plugin to get input from the user. But
        > getchar() returns the same keycode no matter what keymap is activated.
        > So for example:
        >
        > :set keymap=bulgarian-phonetic
        >
        > With this keymap, in insert-mode, typing "b" on a US keyboard inputs
        > "б". But typing "b" in the getchar() prompt always returns 98, and
        > nr2char(98) always returns "b" regardless of the keymap.
        >
        > Is there some other function instead of nr2char() that gets the
        > keymapped character from a keycode?
        >
        > Vim 7.4.35
        >
        > Thanks!
        >
        > Justin M. Keyes

        You can do the lmap-translation yourself

        func! LmapArg(chr)
        let chrtrans = maparg(a:chr, "l")
        return chrtrans=="" ? a:chr : chrtrans
        endfunc


        With enabled keymap
        :echo LmapArg('b')
        б

        Not sure what to do (how to detect) if more than one char needs to be typed to get
        the lmap'ed character.

        (Lame solutions might parse the :redir output of :lmap, or the keymap file)

        --
        Andy

        --
        --
        You received this message from the "vim_use" 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_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • Justin M. Keyes
        ... Thanks! That definitely set me on a useful path. ... Currently I m clumsily looping and comparing maparg() and mapcheck(). Not sure how to figure out if an
        Message 3 of 3 , Jan 6, 2014
        • 0 Attachment
          On Mon, Jan 6, 2014 at 7:35 AM, Andy Wokula <anwoku@...> wrote:
          > Am 05.01.2014 22:28, schrieb Justin M. Keyes:
          >
          >> Hi,
          >>
          >> I am using getchar() in a plugin to get input from the user. But
          >> getchar() returns the same keycode no matter what keymap is activated.
          >> So for example:
          >>
          >> :set keymap=bulgarian-phonetic
          >>
          >> With this keymap, in insert-mode, typing "b" on a US keyboard inputs
          >> "б". But typing "b" in the getchar() prompt always returns 98, and
          >> nr2char(98) always returns "b" regardless of the keymap.
          >>
          >> Is there some other function instead of nr2char() that gets the
          >> keymapped character from a keycode?
          >>
          >> Vim 7.4.35
          >>
          >> Thanks!
          >>
          >> Justin M. Keyes
          >
          >
          > You can do the lmap-translation yourself
          >
          > func! LmapArg(chr)
          > let chrtrans = maparg(a:chr, "l")
          > return chrtrans=="" ? a:chr : chrtrans
          > endfunc

          Thanks! That definitely set me on a useful path.

          > With enabled keymap
          > :echo LmapArg('b')
          > б
          >
          > Not sure what to do (how to detect) if more than one char needs to be typed
          > to get
          > the lmap'ed character.
          >
          > (Lame solutions might parse the :redir output of :lmap, or the keymap file)

          Currently I'm clumsily looping and comparing maparg() and mapcheck().
          Not sure how to figure out if an input sequence has no remaining valid
          completions, so I just bail if maparg() is empty after 3 characters.

          Justin M. Keyes

          --
          --
          You received this message from the "vim_use" 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_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        Your message has been successfully submitted and would be delivered to recipients shortly.