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

Mapping meta key within tmux

Expand Messages
  • Marco
    Hi, I have mappings in my .vimrc that map the Meta-arrow keys noremap + noremap - This works fine in console vim,
    Message 1 of 6 , Jul 12, 2013
    • 0 Attachment
      Hi,

      I have mappings in my .vimrc that map the Meta-arrow keys

      noremap <silent> <M-up> <C-W>+
      noremap <silent> <M-down> <C-W>-

      This works fine in console vim, but it fails when vim is used within
      tmux. Then I get sequences like:

      [1;3Aá]
      [1;3Bá]

      When I call cat -v from the console (TERM=rxvt-unicode-256color) and
      press M-<up> M-<down> I get the following:

      ^[^[[A
      ^[^[[A
      ^[^[[B
      ^[^[[B

      When I call cat -v from the console within tmux
      (TERM=screen-256color) and press M-<up> M-<down> I get the
      following:

      ^[[1;3A
      ^[[1;3A
      ^[[1;3B
      ^[[1;3B

      Which means the terminal interprets the key sequences differently.

      How can I map M-<arrow-keys> to something useful when I run vim in
      tmux?

      Marco

      --
      --
      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.
    • Gary Johnson
      ... The problem is that tmux sets TERM to screen and the key definitions in the terminfo database for screen don t match those of the terminal you are
      Message 2 of 6 , Jul 12, 2013
      • 0 Attachment
        On 2013-07-12, Marco wrote:
        > Hi,
        >
        > I have mappings in my .vimrc that map the Meta-arrow keys
        >
        > noremap <silent> <M-up> <C-W>+
        > noremap <silent> <M-down> <C-W>-
        >
        > This works fine in console vim, but it fails when vim is used within
        > tmux. Then I get sequences like:
        >
        > [1;3Aá]
        > [1;3Bá]
        >
        > When I call cat -v from the console (TERM=rxvt-unicode-256color) and
        > press M-<up> M-<down> I get the following:
        >
        > ^[^[[A
        > ^[^[[A
        > ^[^[[B
        > ^[^[[B
        >
        > When I call cat -v from the console within tmux
        > (TERM=screen-256color) and press M-<up> M-<down> I get the
        > following:
        >
        > ^[[1;3A
        > ^[[1;3A
        > ^[[1;3B
        > ^[[1;3B
        >
        > Which means the terminal interprets the key sequences differently.
        >
        > How can I map M-<arrow-keys> to something useful when I run vim in
        > tmux?

        The problem is that tmux sets TERM to "screen" and the key
        definitions in the terminfo database for "screen" don't match those
        of the terminal you are actually using.

        One way to fix this would be to make tmux set TERM to the name of
        the terminal you are actually using, except that the tmux(1) man
        page says not to do this.

        Another way to fix this is to redefine those keys in your
        ~/.tmux.conf as I have done in mine for function keys.

        # To fix screen terminfo function key entries when using PuTTY:
        #
        # From https://gist.github.com/pickerweng/1713936
        #
        set -g terminal-overrides "*:kf1=\e[11~:kf2=\e[12~:kf3=\e[13~:kf4=\e[14~:kf5=\e[15~:kf6=\e[17~:kf7=\e[18~:kf8=\e[19~"

        Yet another way is to redefine those keys in your ~/.vimrc as I did
        originally fix the same problem.

        " Fix screen's key bindings.
        "
        if &term == "screen"
        " These work from my HP keyboard in PuTTY on Windows XP.
        "
        map <Esc>[D <S-Left>
        map <Esc>[C <S-Right>
        map <Esc>[11~ <F1>
        map <Esc>[12~ <F2>
        map <Esc>[13~ <F3>
        map <Esc>[14~ <F4>
        map <Esc>[15~ <F5>
        map <Esc>[16~ <F6>
        map <Esc>[17~ <F7>
        map <Esc>[18~ <F8>
        map <Esc>[19~ <F9>
        map <Esc>[21~ <F10
        map <Esc>[23~ <F11>
        map <Esc>[24~ <F12>
        endif

        I'll leave it to you to come up with the mappings you need in your
        case, but if you run into problems, I or someone else can help you
        further.

        Regards,
        Gary

        --
        --
        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.
      • Marco
        ... That s not the right approach. Even if it might work, it will break something else. ... I can t figure out the correct command line. The terminfo man page
        Message 3 of 6 , Jul 12, 2013
        • 0 Attachment
          On 2013–07–12 Gary Johnson wrote:

          > > How can I map M-<arrow-keys> to something useful when I run vim in
          > > tmux?
          >
          > The problem is that tmux sets TERM to "screen" and the key
          > definitions in the terminfo database for "screen" don't match those
          > of the terminal you are actually using.
          >
          > One way to fix this would be to make tmux set TERM to the name of
          > the terminal you are actually using, except that the tmux(1) man
          > page says not to do this.

          That's not the right approach. Even if it might work, it will break
          something else.

          > Another way to fix this is to redefine those keys in your
          > ~/.tmux.conf as I have done in mine for function keys.
          >
          > # To fix screen terminfo function key entries when using PuTTY:
          > #
          > # From https://gist.github.com/pickerweng/1713936
          > #
          > set -g terminal-overrides "*:kf1=\e[11~:kf2=\e[12~:kf3=\e[13~:kf4=\e[14~:kf5=\e[15~:kf6=\e[17~:kf7=\e[18~:kf8=\e[19~"

          I can't figure out the correct command line. The terminfo man page
          is a terrible read.

          > Yet another way is to redefine those keys in your ~/.vimrc as I did
          > originally fix the same problem.

          That's what I wanted to do. Actually I have similar mapping as you
          do. But I can't figure out the right mapping for Meta-<arrow-keys>.

          # mappings like these work
          noremap <esc>[27;5;9~ :bnext!<cr>

          # the meta-<up> mapping does not work
          noremap <esc>[1;3A :bnext!<cr>

          > I'll leave it to you to come up with the mappings you need in your
          > case,

          That was actually my question, what these mappings are.

          > but if you run into problems, I or someone else can help you
          > further.

          That would be nice.

          Marco

          --
          --
          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.
        • Thomas E. Dickey
          ... It s vague - saying that the entry has to be a derivative of screen , without saying in what way. A quick check on my Fedora18beta shows that someone s
          Message 4 of 6 , Jul 13, 2013
          • 0 Attachment
            On Friday, July 12, 2013 7:06:23 PM UTC-4, Gary Johnson wrote:
            > The problem is that tmux sets TERM to "screen" and the key
            > definitions in the terminfo database for "screen" don't match those
            > of the terminal you are actually using.
            >
            > One way to fix this would be to make tmux set TERM to the name of
            > the terminal you are actually using, except that the tmux(1) man
            > page says not to do this.

            :-(

            It's vague - saying that the entry has to be a derivative of "screen",
            without saying in what way. A quick check on my Fedora18beta shows
            that someone's setting it to screen-256color.

            "screen" on the other hand provides for the ability to map TERM
            into screen.$TERM if that happens to be available. I added several
            entries to the terminal database to use this feature simply because
            screen never matches any of the terminals exactly (line-drawing,
            color, function keys all have issues).

            tmux does not appear to implement this mapping (If tmux adopted
            that feature, it would be an improvement).

            --
            --
            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.
          • Gary Johnson
            ... I didn t have much time for experimentation when I first replied. Now that I have a little more time, mapping the sequence for proved more difficult
            Message 5 of 6 , Jul 14, 2013
            • 0 Attachment
              On 2013-07-13, Marco wrote:
              > On 2013–07–12 Gary Johnson wrote:
              >
              > > > How can I map M-<arrow-keys> to something useful when I run vim in
              > > > tmux?

              > > Another way to fix this is to redefine those keys in your
              > > ~/.tmux.conf as I have done in mine for function keys.
              > >
              > > # To fix screen terminfo function key entries when using PuTTY:
              > > #
              > > # From https://gist.github.com/pickerweng/1713936
              > > #
              > > set -g terminal-overrides "*:kf1=\e[11~:kf2=\e[12~:kf3=\e[13~:kf4=\e[14~:kf5=\e[15~:kf6=\e[17~:kf7=\e[18~:kf8=\e[19~"
              >
              > I can't figure out the correct command line. The terminfo man page
              > is a terrible read.
              >
              > > Yet another way is to redefine those keys in your ~/.vimrc as I did
              > > originally fix the same problem.
              >
              > That's what I wanted to do. Actually I have similar mapping as you
              > do. But I can't figure out the right mapping for Meta-<arrow-keys>.
              >
              > # mappings like these work
              > noremap <esc>[27;5;9~ :bnext!<cr>
              >
              > # the meta-<up> mapping does not work
              > noremap <esc>[1;3A :bnext!<cr>
              >
              > > I'll leave it to you to come up with the mappings you need in your
              > > case,
              >
              > That was actually my question, what these mappings are.

              I didn't have much time for experimentation when I first replied.
              Now that I have a little more time, mapping the sequence for <M-Up>
              proved more difficult than I expected. I think the secret is to put
              this in your ~/.tmux.conf:

              set -g xterm-keys on

              After doing that, my mappings of <Esc>[1;3A seemed to work.

              HTH,
              Gary

              --
              --
              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.
            • Marco
              ... The combination of xterm-keys and the [1;3A mapping works. Thanks a lot. Marco -- -- You received this message from the vim_use maillist. Do not
              Message 6 of 6 , Jul 15, 2013
              • 0 Attachment
                On 2013–07–14 Gary Johnson wrote:

                > I didn't have much time for experimentation when I first replied.
                > Now that I have a little more time, mapping the sequence for <M-Up>
                > proved more difficult than I expected. I think the secret is to put
                > this in your ~/.tmux.conf:
                >
                > set -g xterm-keys on
                >
                > After doing that, my mappings of <Esc>[1;3A seemed to work.

                The combination of xterm-keys and the <Esc>[1;3A mapping works.
                Thanks a lot.

                Marco

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