tmux: enable mouse scrolling in vim instead of history buffer

I have just started using tmux 1.8 recently, after working with screen for a while. After reading things here and there on the internet, I came up with following ~/.tmux.conf However when I open vim and try to scroll with mouse tmux scrolls through its scroll buffer instead of sending the scroll command to vim. Is there a workaround? Following is my config:

set-option -g default-shell /bin/bash


set -g status-utf8 on
set -g status-keys vi
set -g status-interval 1

set -g prefix `
bind `     send-key `

bind-key -n F9  resize-pane -Z
bind-key -n F11 prev
bind-key -n F12 next-window

bind-key | split-window -h
bind-key - split-window -v
set -s escape-time 0
set -g history-limit 100000

set -g mode-mouse on
set -g mouse-resize-pane on
set -g mouse-select-pane on
set -g mouse-select-window on
set-option -g mouse-utf8 on

set -g status-bg '#666666'
set -g status-fg '#aaaaaa'
set -g status-left ''
set -g status-right ''

set-option -sg escape-time 1

UPDATE:

Found the answer. I had to set my term to xterm, it was getting value of screen. When I do following:

export TERM=xterm

and inside vim:

set mouse=a

I had no issues in scroll inside the file opened in vim under tmux. If I have to scroll to history buffer I do (prefix) [ and then use mouse. It works like a charm!


Adding following to your .vimrc does it.

set mouse=a

This enables mouse in all modes, hence a for all. See vim manpages and http://vim.wikia.com/wiki/Using_the_mouse_for_Vim_in_an_xterm.