1

I recently noticed Alt (meta) + arrow keys in my vim executes certain actions, but only if in tmux for some reason.

  • Alt+Left: Deletes 3 lines. Equivalent to vim d3d but works in INSERT mode.
  • Alt+Right: Deletes 3 lines INSERT line above. Equivalent to vim d3dO.
  • Alt+Up: Go to end of line, INSERT. Equivalent to vim A.
  • Alt+Down: Go back 3 WORDS. Equivalent to vim 3B.

I have not made any related key bindings in my .tmux.conf or .vimrc. These commands aren't in vim register either. What is going on here? What configured these commands?

System Info

  • vim: 8.2.3582
  • tmux: 3.2_a
  • Arch Linux

INSERT mode CTRL-V

Alt+Left    ^[[1;3D
Alt+Right   ^[[1;3C
Alt+Up      ^[[1;3A
Alt+Down    ^[[1;3B

environment variable

:echo $TERM
tmux-256color
6
  • In Vim, enter insert mode and press <C-v>, followed by <A-Left>, followed by <CR>. Do the same for each combo and add a screenshot to your question.
    – romainl
    Commented Nov 20, 2021 at 14:53
  • It sounds like your TERM environment variable is not set correctly and Vim isn't understanding the escape sequences your arrow keys send.
    – Heptite
    Commented Nov 21, 2021 at 5:30
  • @romainl Added more relevant info
    – AKSoo
    Commented Nov 22, 2021 at 3:32
  • Comparing your four bullet points to the four <C-v> outputs should give you a hint of what is happening. The odds that doing the same <C-v> dance outside of tmux having a different result are pretty high. Could you do it and add the result to your post?
    – romainl
    Commented Nov 22, 2021 at 6:24
  • What does ":echo $TERM" inside Vim show?
    – Heptite
    Commented Nov 23, 2021 at 1:22

1 Answer 1

1

I realized that vim was executing terminal codes as commands (happens with Ctrl + arrow keys as well). This happens because base vim only supports xterm fully. For other terminals, modified arrow keys must be set manually:

execute "silent! set <xUp>=\<Esc>[@;*A"
execute "silent! set <xDown>=\<Esc>[@;*B"
execute "silent! set <xRight>=\<Esc>[@;*C"
execute "silent! set <xLeft>=\<Esc>[@;*D"

You can read more about this with :help tmux-integration and arrow_modifiers.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .