Using the tmux vi keybindings to copy and paste between panes is great if you haven't tried it.
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.)
Have you tried k9s [1]?
Just being able to run common operations directly on k8s entities is so much better than having to run a separate command.
It also uses vi-style hotkeys.
That's a fair point! The kubernetes example I gave is somewhat contrived, but I will say that I prefer to have whatever resource id I'm working with in my clipboard vs. relying on myself to select the correct one in a tab completion menu.
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`.
Can you give me the bare minimum tmux config that does what you are saying? ALl these tutorials in this thread don't do anything (i just installed tmux and I'm using iTerm 3 and oh-my-zsh on OSX). I'm assuming because my tmux config is empty (I also dont want to disable other features like the original link because I use tmux for actually attaching to sessions)
AFAIK, you'll need to have at least `setw -g mode-keys vi` in your ~/.tmux.conf file to allow tmux to use vi keybindings in copy mode (`Ctrl+b ]`). Make sure to fully exit all tmux sessions and start a new session after making that change.
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.
I type `Ctrl+b [` and in top right it says [0/1] (even if i have a history of say 5 commands). when i press any vim knpfb keys the cursor doesn't do anything. I feel retarded
The parent describes how to do this with tmux right out of the box -- you don't need anything in your config to get this to work. Did you start tmux? If you haven't set up iTerm to connect to a tmux session by default, any new tabs/splits you make won't be running it. You should be able to tell by the presence of the status bar at the bottom.
I type `Ctrl+b [` and in top right it says [0/1] (even if i have a history of say 5 commands). when i press any vim knpfb keys the cursor doesn't do anything. I feel retarded
This sounds terribly convoluted compared to turning on mouse mode and selecting the text with your mouse. It should copy immediately after you release the button, and you should be able to paste with your standard shortcut if you set up tmux to use the clipboard of your choice.
Mouse-driven flows are always a little more intuitive and discoverable, but keyboard shortcuts are more precise and can be lightning fast once you have muscle memory.
Listed the way the parent does it seems very complicated, but if you have the sequence memorized and trained it can be executed very quickly and without moving your hands from the keyboard.
Ah! Thanks for pointing that out. That's the piece I forgot about here. iTerm is populating the system clipboard from tmux because of the tmux integration [1].
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:
(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.)