9

I'm using macvim inside tmux inside iTerm2. Basically I just want to be able to scroll the buffer using the mousewheel. I've set

set -g moude-mouse on

in my .tmux.conf, and

set mouse=a
set ttymouse=xterm2

in my .vimrc. Additionally I enabled 'xterm mouse reporting' in iTerm2.

Whenever I use the mouse wheel, vim will switch to insert mode and insert seemingly random characters. I'm guessing vim can't correctly interpret the mouse escape-codes.

The problem also appears outside of tmux and in the default Terminal.app which leads me to believe that it's a vim issue.

I've expiremented with all possible values of ttymouse, none had the desired effect.

1 Answer 1

12

Ah, I found the culprit by bisecting my .vimrc file. I had mapped Escape in normal mode to clear search highlighting:

" Clear highlighting on escape in normal mode
nnoremap <esc> :noh<return><esc>

However, that will confuse vim as it tries to parse the mouse's escape codes. So what I ended up doing is taking the solution from this answer, and also mapping:

" needed so that vim still understands escape sequences
nnoremap <esc>^[ <esc>^[

Which will fix that issue.

1
  • this saved me from a lot of pain -- deserves to be in vim docs or somewhere prominent. Apr 3, 2017 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.