Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending Ctrl-Right to Vim inside Tmux

Tags:

vim

tmux

I'm using Vim that's running inside a tmux session. Within Vim, I have Ctrl-Right bound to :tabnext:

map <C-right> :tabnext<CR>      "next tab

I want to be able to invoke this binding even when Vim is inside tmux, so I added the following to my .tmux.conf:

bind-key -n C-Right send-keys C-Right

But this doesn't have any discernible effect on either Tmux or Vim! What am I doing wrong here?

Thanks in advance.

like image 905
Mayank Avatar asked May 19 '13 20:05

Mayank


1 Answers

I got something working though I'm very much treading unknown territory here. Perhaps someone else can fill in the rest.

The first difference I noticed when starting up Vim in the terminal and Vim inside tmux was in their 'term' setting.

When asked :set term?, ordinary terminal Vim answered xterm-256color, but tmux Vim answered screen. It's important to understand that the exact key codes sent in the terminal depend on the type of the terminal.

One solution is simply to make tmux and Vim speak the same language. In tmux:

set-option -gw xterm-keys on
bind-key -n C-Right send-keys C-Right

In Vim:

:set term=xterm-256color

Now Vim and tmux understand each other's terminal key codes and your key strokes will make it all the way to Vim.

like image 110
glts Avatar answered Sep 24 '22 18:09

glts