Increased Developer Productivity with Tmux, Part 8: Copy mode.
Tmux's copy mode
In Part 7 I finished up showing how using Elinks allows you to reduce context switching. In this episode I go over getting proficient within copy mode. Copy mode is a state where you can "freeze" a pane or window with the intention of reading the output. In this mode you can scroll, search, and copy the text of a pane or window. Subduing copy mode is an absolute must if you are going to maximize your productivity with Tmux.
Subduing copy mode is an absolute must if you are going to maximize your productivity with Tmux.
- To start I open my Tmux conf file at
~/.tmux.conf
. I have vi-bindings enabled in copy mode. - I switch over to a Tmux window within a Rails console, in which I will demonstrate a simple copy and paste.
- To enter copy mode I issue a
<prefix> + [
- Using the motion keys I scroll up to the capital "T" and hit the space key to start a highlighted block (i.e. "begin selection"). I use movement keys to get to the end of the command and hit "Enter". That will save the highlighted text to the Tmux clipboard.
- To paste from the Tmux clipboard type
<prefix> + ]
- Most times we are not concerned with copying and just want to see the output within a pane or window.
- To be sure to capture all of the output from say a stack trace or XML dump, set the scroll history high in the config file.
- As previously mentioned, I can use familiar Vim bindings to navigate around copy-mode. Here are some that I use regularly.
Control-U
— pages upControl-D
— pages up^
— goes to the beginning of a line$
— goes to the end of a lineg
— goes to the beginning of scroll historyG
— goes to the end of scroll history/
— search down?
— search up- I switch to my Elinks window and hit the
v
key to start a selection. - To prove that the selection is in the system clipboard and not just the Tmux clipboard. I paste the selection into a MacVim, which is running outside of Tmux.
- Lastly, here is a Vim leader mapping for pasting from the system clipboard easily.
Tmux operates in a client server design, therefore, the Tmux clipboard can be centrally accessed from any of the client sessions. That said, this ability only goes so far. It is vital that there is a way to copy to the system or OS clipboard. Keep reading and I will show you how for OSX.
Let's get back to the topic of copying and pasting to the system clipboard. For OSX I want to recommend this thoughtbot article, which leverages the Tmux 1.8 copy-pipe
feature. Copying to the system clipbord starts at 7:01 mark in the screencast.
# This is what the "y" key is bound to in my .tmux.conf file # Copy to OSX clipboard bind-key y run-shell "tmux save-buffer - | reattach-to-user-namespace pbcopy"
That concludes installment 8. Tmux copy mode
Copy mode is a mode you are going to be in very often, therefore, make it a point to get proficient within it. Memorize the keys for getting into copy mode as well as the keys for movement. Ideally, you are using Emacs or Vim from within Tmux and can use their bindings for copy mode movement. If not try to get some bindings that make moving around in copy mode painless. Finally, remember that Control-C
gets you out of copy mode and is another important key combination to muscle-memorize.
Next in part 9, which will be the final in the series, I instruct on using Tmux within Terminal.app. While you are waiting for the article check out the screencast that is already cooked.
If you like this article and screencast go to the dedicated page for this series at http://minimul.com/teaches/tmux.
- Pushed on 07/14/2014 by Christian