When I switched from GNU Screen to Tmux, I was just jazzed that Tmux had a status bar. To achieve that same effect in Screen I had a cryptic 115-character hardstatus
string that I copy–pasted from someplace lost to the annals of the Internet Archive.
It wasn’t too long after I made the switch until I felt that old hacker itch and began scouring Github for Tmux tips.
You can view my complete tmux.conf
on my github
Tmux Tips for the Uninitiated ¶
Ctrl
-f
Meta is for super starsI used to always bind
Ctrl
-a
to Meta to make Tmux behave like Screen; however, when you use Screen inside Tmux (as I often do with our AWS servers), hittingCtrl
-a
a
can get pretty tiresome. Plus, you can’t use Readline very effectively withoutCtrl
-a
Faster escape
When I first started using Tmux I couldn’t stand the amount of time it took to enter copy-mode. Then I realized—I didn’t have to.
Maximize Panes
One of the things I love about Vim splits is that you can hit
Ctrl-w
|
to maximize the current pane and hitCtrl-w
=
to bring it back to an even split. Bringing that functionality to Tmux is very powerful and super easy. This line will let you hitMeta
|
to maximize a single pane and then hitMeta
|
again to bring it back to the original split.Warning: this is a tip that will only work with tmux 1.8+ (check your version via
tmux -V
)Vim-esque system clipboard copy–paste
Sometimes system clipboard support from Vim isn’t enough. It’s convenient to be able to pull whatever is in your Tmux buffer onto your system clipboard (preferably without having to memorize any new keybindings and without overwriting any existing keybindings).
First, I set the window mode-keys to use Vi bindings:
Next, I bind
Meta Esc
to enter Tmux copy-mode:After that, I bind visual-selection and copy keys inside vi-copy mode to their Vim equivalents:
Finally, I bind
Meta y
to execute a shell command. This should work on either Linux or OSX, although I’ve only tested this on OSX:if-shell 'test "$(uname -s)" = "Darwin"' 'bind-key y run-shell "tmux show-buffer | pbcopy" \; display-message "Copied tmux buffer to system clipboard"' if-shell 'test "$(uname -s)" = "Linux"' 'bind-key y run-shell "tmux show-buffer | xclip -sel clip -i" \; display-message "Copied tmux buffer to system clipboard"'
OSX Specific Tmux file
Even though Tmux and Vim are really popular on OSX—they are, essentially, broken. You have to do the whole
reattach-to-user-namespace
thing to get Vim’s clipboard to play nicely inside Tmux. This mess makes yourtmux.conf
look more cluttered and makes your dotfiles a little less portable. To fix this I keep an OSX Specifictmux.conf
.Steve Losh’s Bad Wolf Status Bar
News Flash: Steve Losh makes cool looking stuff. In Steve’s version of this he uses a small script to get his unread email count from his local offlineimap folder. In the version below I use a little bash script I wrote to grab weather info (that I call weathermajig).
# Bad Wolf by Steve Losh # ===================== set -g status-fg white set -g status-bg colour234 # set -g status-bg default #set for transparent background set -g window-status-activity-attr bold set -g pane-border-fg colour245 set -g pane-active-border-fg colour39 set -g message-fg colour16 set -g message-bg colour221 set -g message-attr bold # Custom status bar # Powerline set -g status-left-length 32 set -g status-right-length 150 set -g status-interval 5 # Lets add the current weather to our status bar—why? Well Why the french-toast not? set -g status-left '#[fg=colour16,bg=colour254,bold] #S #[fg=colour254,bg=colour238,nobold]#[fg=colour15,bg=colour238,bold] #(weathermajig boulder --short) #[fg=colour238,bg=colour234,nobold]' set -g status-right '#[fg=colour245]❬ %R ❬ %d %b #[fg=colour254,bg=colour234,nobold]#(rdio-current-track-tmux)#[fg=colour16,bg=colour254,bold] #h ' set -g window-status-format "#[fg=white,bg=colour234] #I #W " set -g window-status-current-format "#[fg=colour234,bg=colour39]#[fg=colour16,bg=colour39,noreverse,bold] #I ❭ #W #[fg=colour39,bg=colour234,nobold]"
Great stuff Tyler. Quick question, on a mac are you able to just hit Meta then a tmux command? It looks like you bound ctrl-f to the prefix but I can’t figure out how to get the option key on iTerm2 to send ctrl-f. Thanks for the article!
@peterhbaker:disqus I’m able to hit C-f and then a tmux command in iTerm 2. e.g., C-f c creates a new window for me.
Cool. I was wondering if you had found the magic where one could just to option-c to create a new window. I manually mapped all keys that I could to meta but just looking for a better way!
Thanks for getting back to me!