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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to