Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Enable mouse mode in tmux

    Bonnie EisenmanBonnie Eisenman

    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.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    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.

    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.

    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.

    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.

    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.

    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.

    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.

    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.