33

I'm running VIM in tmux,

When I'm try to select a range of texts in VIM, the mouse kept resetting its position, thus I can only select one line (the last line where mouse occurs).

Does anyone know how to solve this?

2 Answers 2

49

There are two settings that you need to configure for this to work.

  1. In your .vimrc add:

    set ttymouse=xterm2
    set mouse=a
    
  2. In your .tmux.conf add:

    set -g mouse on
    

You will then be able to use the mouse to select blocks of text, resize splitted windows, ...

5
  • Hmm, mouse is slower in tmux, I can feel that, but it works anyway Commented Oct 13, 2012 at 0:29
  • 9
    Try to set ttymouse=xterm2 in your vimrc. For my setup (urxvt-unicode, tmux) it vastly improved the speed and responsiveness of mouse selecting in vim/tmux. Commented Aug 15, 2014 at 12:04
  • @imbaer Thanks, the mouse did not work at all in vim until I set that var as well. Commented Jul 30, 2015 at 18:20
  • As mentioned in the other answer, tmux.conf should now use set -g mouse on Commented Nov 7, 2018 at 0:19
  • Note that the ttymouse option was removed in neovim: github.com/neovim/neovim/issues/2725 Commented Mar 25, 2023 at 8:13
9

The answer by @jasonwryan won't work as of tmux 2.1 since the several mouse options were merged into one configuration called mouse.

The new approach is:

  1. In your .vimrc add:

    set ttymouse=xterm2
    set mouse=a
    
  2. In your tmux.conf add:

    set -g mouse on
    

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.