Enable mouse mode in tmux

Bonnie Eisenman
InstructorBonnie Eisenman
Share this video with your friends

Social Share Links

Send Tweet
Published 8 years ago
Updated 6 years ago

We'll learn how to use mouse mode in tmux, including enable mouse control for resizing, scrolling and selecting panes. We'll also set keybindings in our tmux configuration to control mouse mode.

[00:00] Something you may have noticed about tmux is that with my current setup I can't actually use my mouse to control anything. When I click between panes, nothing happens. Some people don't mind that, but for a lot of us it's nice to be able to have mouse control as an option, even if we primarily use keyboard input.

[00:16] I'm going to type prefix and then the colon key. Remember this will either be Ctrl-b or Ctrl-a if you remapped your keys as we did in the previous lesson. Then I'm going to type set mouse on. Now you'll see that I can click between panes to change which one is my active one instead of the other method that we have, which is doing prefix key and then the arrow key to switch between panes.

[00:39] I can also use my mouse to resize my panes. If I click on the divider bar and then drag, you can see that I can dynamically resize my windows instead of having to specify it again from the command menu in tmux. One other neat trick, I can finally use the mouse to scroll. Your native scrolling will also work when you have mouse mode on.

[01:02] The commands for mouse mode changed in version 2.1 from October 2015. If you're using a version earlier than that, you're going to have to enable these three functionalities separately with different commands.

[01:12] It might be a little bit annoying to always have mouse mode on. As you can see, it means that our cursor changes, and you have this weird highlighting, and you can accidentally screw with your pane barriers. Let's enable some hot keys to easily turn it on and off.

[01:24] I'm going to open my tmux.conf file using vim. Now let's add another section here. This one is going to be for mouse mode keys. I'm going to bind the m key to set -g for global mouse on. Then I'm going to bind the M key for set with -g for global mouse off. I'm going to save this. Remember I have a hot key for reloading the tmux.config. Now I can do Ctrl-a r. It will reload the config.

[01:58] Now that we've made that change and reloaded our config, you can see right now I'm still in mouse mode. I can resize the pane with my cursor. If I type Ctrl-a M, I'm no longer in mouse mode, that this is no longer effective. I can get back into mouse mode with Ctrl-a m.

[02:16] Having these shortcuts is just a nicety, but you might find that you want to add them. If so, feel free to edit your tmux.conf file.