jcard
Joined 7 years ago
Joined 7 years ago
Where I really like this tmux copy/paste workflow is for grabbing multiple lines of command output. From there I can paste that into some message on slack, or use it as the body of a PR message that describes some error or shows some output.
For the latter case, I have a zsh function that calls `hub` to open a PR, drops me off into vim, and once I `:wq`, it will send the API request to open the PR, and then open my browser up to it. This is the command I have in the function: `hub pull-request --push --file "$filename" --browse --draft`.
As long as your system & version of tmux supports copying to the local clipboard, you should have no problems pasting with either Ctrl/Cmd+v or `Ctrl+b ]`.
Otherwise, if the clipboard is broken for some reason, you can stick to using `Ctrl+b ]` to paste.
This copy/paste workflow is really nice for working with kubernetes on the command line.
E.g., imagine that you need to delete a kubernetes pod.
You'd run a few commands like this:
1. `kubectl get pods`
2. Find the pod id, and copy it using mouse & some shortcut
3. `kubectl delete pod <pasted-pod-id>`
Instead of this mouse workflow, you could do something like this in tmux:
1. `kubectl get pods`
2. Find pod id, `Ctrl+b [` to enter tmux's vi selection mode
3. Navigate to the section you'd like to copy; e.g. `k6ww` (up six lines and over two words, for example)
4. Press space bar to start selection, and use common vim movements to highlight what you'd like to copy (e.g. w or $)
5. Press return/enter to copy the selection
6. This text can be pasted with either Cmd/Ctrl+v (it gets copied to the system clipboard for me on macOS 11.2.1 with tmux 3.1c_1 from brew), or using the default tmux shortcut `Ctrl+b ]`. So that would allow you to type `kubectl delete pod Ctrl+b ]`.
So yeah, it's a few more steps, but it's a lot faster for me.
These are the relevant sections of my ~/.tmux.conf file:
# Use vim keybindings in copy mode
setw -g mode-keys vi
# Use emacs keybindings in the status bar
set -g status-keys emacs
(I mention the `set -g status-keys emacs` config line just as an FYI since it's been really helpful for me with tmux. I've never liked using readline-type inputs with vi-mode.)
I have basically the same setup as you, and I think that's the only thing I've manually configured. I also run the oh-my-zsh tmux plugin, and iTerm2's tmux integration, which seemed to work out of the box for me.