Tmux: Disable Mouse When Entering Vim

Tmux: Disable Mouse When Entering Vim

Where ever I say vim, its vim inside tmux.

Current scenario: I have mouse disabled in vimrc and enabled in tmux.conf. Mouse scrolls inside vim, use tmux-mouse to scroll and thus scrolls through history.

Case-1
If I disable mouse in tmux also (vim=off, tmux=off), then scrolls result in movement of cursor (cursor-positioning) in vim in tmux.

Case-2
If I enable mouse in vim also (vim=on, tmux=on), then I face problems with copying, which I don't want. So my requirement is to keep mouse off in vim.

The target is to use scrolling in tmux only, while in vim scrolling should move the cursor (which kind-of scrolls when the cursor reaches the edge of page, which is the default configuration).

My question is that is there a way to set the behavior so as to disable mouse scrolling in vim (so that the default behaviour works, ie scrolls move the cursor) when I enter vim in tmux, only in the pane which has vim and re-enable it when I exit vim.

In more simpler terms, keeping tmux=on, vim=off, turn off the effects of tmux=on in vim and thus scrolls result in cursor positioning.

0

2 Answers

I used this plugin: tmux-better-mouse-mode and turned on this flag in .tmux.conf:

set -g @emulate-scroll-for-no-mouse-alternate-buffer "on"

This worked exactly the way I required.

This question is very poorly worded.

It is not clear whether you want the mouse to work in vim or not.

If you do, you just need to configure vim to turn it on - if you do, then tmux will send mouse events in the pane running vim to vim rather than handling them itself.

If you don't want the mouse to work in vim, it should be enough to turn it off in vim. That means vim will not request the mouse from tmux and so tmux will not send mouse events to the pane.

3

Your Answer

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

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.