Tmux is becoming pretty popular as of late, but as with any new technology, there are skeptics. I’m here to quell some rumors and outline how to start using Tmux effectively.
Out of all the questions I get, the most common is, “Does copying and pasting work in Tmux? I heard it wasn’t possible.” Forget that noise; copying and pasting works wonderfully with a couple of extra steps.
If you’re using Homebrew, run:
brew install reattach-to-user-namespace
If you’re not, head to the
repository and follow
the instructions to compile yourself. Be sure to check
out Chris Johnsen’s great
reattach-to-user-namespace is actually doing.
Open up your Tmux configuration (typically at ~/.tmux.conf) and throw this line at the top of the file:
set-option -g default-command "reattach-to-user-namespace -l zsh"
This assumes that you’ve installed reattach-to-user-namespace (and it’s in
$PATH) and that you’re using zsh. Every time you open a new window or
pane, it’ll run
reattach-to-user-namespace, which digs into some of Apple’s
inner-workings to enable pbcopy and pbpaste support.
If you’re using Vim in a terminal, set your clipboard to the unnamed clipboard
(make sure it’s not wrapped in a conditional
If you want copying and pasting to work from your Tmux buffers, you may want to run something similar to this:
#!/bin/sh while true; do if test -n "`tmux showb 2> /dev/null`"; then tmux saveb -|pbcopy && tmux deleteb fi sleep 0.5 done
That’ll look to see if there are any buffers in tmux; if there are, it’ll copy it into the system clipboard and delete the buffer. This is really handy if you’re trying to grab a backtrace or the output from a command.