This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Customize tmux with tmux.conf

    Bonnie EisenmanBonnie Eisenman

    You can modify tmux's behavior with your tmux configuration file, .tmux.conf. You can use your tmux config to change color schemes, set custom keybindings, set defaults, modify the status bar, and more. In this lesson, we'll change some of the default color options as well as modify the prefix key.

    Code

    Code

    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
    Transcript

    Transcript

    00:00 We can modify tmux's default behavior by editing your tmux configuration file, which we can do by editing the .tmux.conf file in your home directory. The first modification we're going to make is changing the prefix key combination for tmux. Ctrl-b is fine, but it's a little bit annoying to type. I'm going to remap it to Ctrl-a, which is a more natural key binding.

    00:25 I'm going to add a comment -- rebind prefix key. Then we're going to type unbind C-b. Then we use the command set option -g -- for global -- prefix. We want our new key to be C-a. We unbound C-b. We set the new option to have C-a as our prefix. Finally, we're going to bind C-a send-prefix. I'm going to save that.

    00:58 If you ever want to look up which commands you can use in your tmux configuration, check out the man page. Now that we've edited our configuration file, we'll need to make sure that tmux is restarted.

    01:09 If we look at tmux ls, we can see that we have a scratch session currently running. I'm going to kill that session by typing tmux kill-session -t and then the session name, which in this case is scratch. If I run tmux ls again, we'll see that no tmux server is currently running, which is great because now when we restart tmux it will pick up our changes to the configuration file.

    01:34 Let's test it out. I'm going to run tmux. I'm in a new session. It's session 0I can type Ctrl-a and then double quote to open a new pane. Before, I would have had to type Ctrl-b. Now I can use Ctrl-a to do all of the normal tmux commands that we would use the prefix key for.

    01:55 We can also use the tmux configuration to edit the theme of tmux, so changing the colors, that sort of things. Let's say that we want to change the status bar's color. We can say set -g -- for globally for tmux -- status-bg. Let's set it to blue. Then let's set the foreground color to white.

    02:19 If we save this again and go back into tmux with tmux attach...In order to pick up the changes to our tmux configuration file, we could restart tmux. But we could also do prefix and colon to go into command mode, and then tell tmux to source-file, and point it to our updated configuration file.

    02:41 Now it loaded the new configuration file. You can see that the color of our status bar reflects the update. You might see a lot of different tmux configs online. You might be tempted to download one and try it out for yourself.

    02:53 That's definitely one way to learn how to customize your tmux, but I think it's much more helpful to build up a personalized tmux config file slowly, one modification at a time so that you really understand what's going on. If you are planning on doing that, I highly encourage you to add another shortcut to your tmux config.

    03:13 Just like we told tmux to source our config file again, we can bind a key to issue that same command -- so bind, and then I'm going to do R source-file, and point it to this tmux configuration. Now, when you run tmux, you'll be able to quickly see the effects of your changes.

    03:35 One last note is that you should definitely take a look at the man page for tmux and view the default bindings to figure out what the existing options are and which commands you can use to run. Armed with that knowledge, you'll be able to set up tmux to work exactly the way you want it to.

    Discuss

    Discuss