Increased Developer Productivity with Tmux, Part 5: Send-keys command
Leveraging the Tmux send-keys command
In Part 4 I covered Tmux starter templates. In this edition, I display the power of the send-keys
command. In a nutshell the send-keys command enables you to send a command to another window and/or pane. When understood this command will sky-rocket your productively, principly by keeping important output easily visible while your focus "stays put" in your primary working window pane. I will start teaching the most common ways to use send-keys, which is within a single window split vertically, but will also instruct on how to send commmands to other windows.
Let's explore the wonderful send-keys command.
- To get started I launch Tmux with two windows, the first being vertically split in two.
- I then run the command
grunt watch
in the right pane while staying in the left pane. - The previous step simply sends the command to the right pane but to send and run the command I need to also send
C-m
. - Next, I open the Gruntfile.js in Vim and make some edits to the watch section. From the editor I send a "close and re-run
grunt watch
" command to the right pane to test my changes while never leaving my editor. - How about using
send-keys
to beam commands to other windows? - Since send-keys is such an important part of my productivity arsenal I created a bash function to quickly call it.
- Another common workflow of mine is to edit code in the left pane and to run specs in the right pane. I do this in combination with the bash function above and a Vim leader command.
- Another way I leverage send-keys is to run a
git diff
after starting to write (but then forgetting what key modifications are in this commit) my git commit message. I don't need to exit out of the commit message because I can send-keys over agit diff
to the right pane.
I never use send-keys to send commands to other windows but thought I would demonstrate as there might be some edge cases where this is helpful. By far the most important use of send-keys is to send commands to other panes within the current working window. So much so that I created a bash function to assist me. Read on.
function ts { args=$@ tmux send-keys -t right "$args" C-m }
maprt :w :call RunCurrentTest('!ts be rspec') map rl :w :call RunCurrentLineInTest('!ts be rspec')
.vimrc
That concludes installment 5. The Tmux send-keys command
I can't stress enough the importance of this commmand and I would consider it near top of the list in twisting Tmux to increase your productivity. Next in part 6 I teach on using the console-based browser, Elinks. While you are waiting for the article check out the screencast that is already baked.
If you like this article and screencast go to the dedicated page for this series at http://minimul.com/teaches/tmux.
- Pushed on 06/23/2014 by Christian