Moving panes between tmux sessions is something that makes tmux a very flexible
and powerful tool. I don’t need this feature very often, but it comes in
clutch when you need it.
Pull a pane from any other session # [1]
Using choose-window I was able to come up with a way to select any pane
withing any other session and join it into my current session.
# Choose a pane to join in horizontally
bind f choose-window -Z 'join-pane -h -s "%%"'
Push/Pull from scratch # [2]
I’ve long had this one in my tmux config, I always have a “scratch” session
that I’m running, I often use for looking at things like k9s accross repos
within a popup.
This use case puts a pane into the scratch session, then pulls it back out. I
will use this to move a pane between sessions in the rare cases I need to do
this.
# push the active pane into the scratch session horizonally
bind -n M-f join-pane -ht scratch
# pull the last active pane from the scratch session horizonally into this session
bind -n M-F join-pane -hs scratch
References:
[1]: #pull-a-pane-from-any-other-session
[2]: #pushpull-from-scratch
Posts tagged: tmux
All posts with the tag "tmux"
24 posts
latest post 2022-12-04
Publishing rhythm
I love the freedom of writing in markdown. It allows me to write content from
the comfort of my editor with very little focus on page style. It turns out
that markdown is also a fantastic tool for creating slides.
Present from the terminal # [1]
I will most often just present right from the terminal using
lookatme [2]. Presenting
from the terminal lets me see the results quick right from where I am editing.
It also allows me to pop into other terminal applications quickly.
reveal.js # [3]
I sometimes also use reveal.js, but that’s for another post. It is handy that
it lives in the browser and is easier to share.
New Slides # [4]
I leverage auto slides when I write my slides in markdown. The largest
heading, usually an h2 for me, becomes the new slide marker. Otherwise my
process is not much different, It just becomes a shorter writing style.
Installation # [5]
lookatme is a python library that is available on pypi, you can install it with
the pip command.
python -m pip install lookatme
Since it’s a command line application it works great with pipx. This prevents
the need to manage virtual environments yourself or ending up with packages
clashing in your system python e...
I recently found a really great plugin [1] by
mhinz [2] to open files in neovim from a
different tmux split, without touching neovim at all.
Installation # [3]
neovim-remote [1] is not a neovim
plugin at all, it’s a python cli that you can install with pip. Unlike
the repo suggests, I use pipx to install nvr.
pipx install neovim-remote
How I use it # [4]
I have this added to my .envrc that is in every one of my projects.
This will tie a neovim session to that directory, and all directories
under it.
export NVIM_LISTEN_ADDRESS=/tmp/nvim-$(basename $PWD)
In my workflow I open a tmux session for each project, so this
essentially ties a neovim session to a tmux session.
Open neovim # [5]
First open neovim, but with the nvr command. This will open neovim,
and look pretty much the same as always.
nvr
If you try to run nvr again in another shell nothing will happen as
its already runnin under that address, but if you give it a filename it
will open the file in the first instance of neovim that you opened.
nvr readme.md
Links # [6]
- GitHub [1]
References:
[1]: https://github.com/mhinz/neovim-remote
[2]: https://github.com/mhinz
[3]: #installation
[4]: #how-i-use-it
[5]: #op...
As I am toying around with textual, I am wanting some popup user input
to take over. Textual is still pretty new and likely to change quite
significantly, so I don’t want to overdo the work I put into it, So for
now on my personal tuis I am going to shell out to tmux.
The Problem # [1]
The main issue is that when you are in a textual app, it kinda owns the
input. So if you try to run another python function that calls for
input it just cant get there. There is a
textual-inputs [2] library
that covers this, and it might work really well for some use cases, but
many of my use cases have been for things that are pre-built like
copier, and I am trying to throw something together quick.
textual is still very beta
Part of this comes down to the fact that textual is still very beta and
likely to change a lot, so all of the work I have done with it is for
quick and dirty, or fun side projects.
The Solution # [3]
So the solution that was easiest for me… shell out to a tmux popup.
The application I am working on wants to create new documents using
copier templates. copier has a fantastic cli that walks throught he
template variables and asks the user to fill them in, so I just shell...
The default keybinding for copy-mode <prefix>-[ is one that is just so
awkward for me to hit that I end up not using it at all. I was on a
call with my buddy Nic this week and saw him just fluidly jump into
copy-mode in an effortless fashion, so I had to ask him for his
keybinding and it just made sense. Enter, that’s it. So I have addedt
his to my ~/.tmux.conf along with one for alt-enter and have found
myself using it way more so far.
Setting copy-mode to enter # [1]
To do this I just popped open my ~/.tmux.conf and added the following.
Now I can get to copy-mode with <prefix>-Enter which is control-b Enter, or alt-enter.
bind Enter copy-mode
bind -n M-Enter copy-mode
More on copy-mode # [2]
I have a full video on copy-mode you can find here.
tmux copy-mode [3]
References:
[1]: #setting-copy-mode-to-enter
[2]: #more-on-copy-mode
[3]: /tmux-copy-mode/
One of the first things I noticed broken in my terminal based workflow moving
from Windows wsl to ubuntu was that my clipboard was all messed up and not
working with my terminal apps. Luckily setting tmux and neovim to work with
the system clipboard was much easier than it was on windows.
First off you need to get xclip if you don’t already have it provided by your
distro. I found it in the apt repositories. I have used it between Ubuntu
18.04 and 21.10 and they all work flawlessly for me.
I have tmux setup to automatically copy any selection I make to the clipboard
by setting the following in my ~/.tmux.conf. While I have neovim open I need
to be in insert mode for this to pick up.
# ~/tmux.conf
bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -i -f -selection primary | xclip -i -selection clipboard"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xclip -selection clipboard -i"
To get my yanks to go to the system clipboard in neovim, I just added
unnamedplus to my existing clipboard variable.
# ~/.config/nvim/init.vim
set clipboard+=unnamedplus
If you need to copy something right from the terminal you can use xclip
directly. ...
I have added a hotkey to my copier template setup to quickly access all my
templates at any time from tmux. At any point I can hit <c-b><c-b>, thats
holding control and hitting bb, and I will get a popup list of all of my
templates directory names. Its an fzf list, which means that I can fuzzy
search through it for the template I want, or arrow key to the one I want if I
am feeling insane. I even setup it up so that the preview is a list of the
files that come with the template in tree view.
bind-key c-b popup -E -w 80% -d '#{pane_current_path}' "\
pipx run copier copy ~/.copier-templates/`ls ~/.copier-templates |\
fzf --header $(pwd) --preview='tree ~/.copier-templates/{} |\
lolcat'` . \
"
I’ve had this on my systems for a few weeks now and I am constantly using it
for my tils [1],
blogs [2], and my .envrc file that goes into
all of my projects to make sure that I have a virtual environment [3] installed and
running any time I open it.
[4]
References:
[1]: https://waylonwalker.com/til/
[2]: https://waylonwalker.com/archive/
[3]: /virtual-environment/
[4]: https://images.waylonwalker.com/copier-templates-tmux-popup.png
tmux popups can be sized how you like based on the % width of the
terminal on creation by using the flags (h, w, x, y) for height, width,
and position.
# normal popup
tmux popup figlet "Hello"
# fullscreen popup
tmux popup -h 100% -w 100% figlet "Hello"
# 75% centered popup
tmux popup -h 100% -w 75% figlet "Hello"
# 75% popup on left side
tmux popup -h 100% -w 75% -x 0% figlet "Hello"
Sorry, your browser doesn't support embedded videos.
example running these commands
Uses
This is a listing of all the things that I use on a daily basis to build data
pipelines, lead my team, and build this website.
older editions # [1]
[[ uses-2021 ]]
Installation # [2]
Everything installed on my machines is done through ansible-playbooks. It’s
been a long transformation to get here, but its so satisfying to boot a brand
new system, run a single command a have every single thing cofigured exactly to
my liking.
# GET is available by default on Ubuntu
GET waylonwalker.com/bootstrap | bash
# For debian based systems without GET by default
sudo apt install curl
curl -F https://waylonwalker.com/bootstrap | bash
OS # [3]
I run Ubuntu, it works well for me without too much fuss. For me the
distribution does not really matter too much, I’m more interested in what’s
inside.
Window Manager # [4]
I use awesome wm. Awesome is a tiling window manager that alows me to navigate
through 9 workspaces (technically called tags in awesomewm). I can script out
certain applications...
tmux targeted session
https://youtu.be/5KE7Il7SOEk
This is something that I made up but use every single day, this is what keeps
much of what is on my blog or my teams private work wiki going. I have a few
very important directories that I have assigned directly to a hotkey for fast
session switching.
bind -n M-i new-session -A -s waylonwalker_com "cd ~/git/waylonwalker.com/ && nvim"
bind i popup -E -h 95% -w 95% -x 100% "tmux new-session -A -s waylonwalker_com 'cd ~/git/waylonwalker.com/ && nvim'"
bind -n M-I popup -E "tmux new-session -A -s waylonwalker_com 'cd ~/git/waylonwalker.com/ && nvim'"
tmux new-session [1]
This one is building off of yeserday’s new-session post, make sure you check that one out as well.
How I navigate tmux in 2021 [2]
for more information on how I navigate tmux, check out this full post
Also check out the full YouTube
tmux-playlist [3]
to see all of the videos in this series.
References:
[1]: /tmux-new-session/
[2]: /tmux-nav-2021/
[3]: https://www.youtube.com/playlist?...
tmux detach
https://youtu.be/A1qx3tNKDdA
tmux detach is a handy tmux command that will quit your current session while
keeping it running. The full name of the comamnd is detach-client, detach
is a shorthand.
default keybinding
bind-key d detach-client
I have mine bound to mod+d where mod is alt.
bind -n M-d detach-client
https://waylonwalker.com/tmux-nav-2021/
for more information on how I navigate tmux, check out this full post
Also check out the full YouTube
tmux-playlist [1]
to see all of the videos in this series.
References:
[1]: https://www.youtube.com/playlist?list=PLTRNG6WIHETB4reAxbWza3CZeP9KL6Bkr
tmux attach
https://youtu.be/JQ0yDCVu44E
attach is one of the most useful features of tmux. If you have no interest in
tmux for pane and window management, you should use tmux for this. It can be a
life saver if you ever get disconnected from the host machine or accidently
close your terminal you can connect right back into the session you were just
in using attach.
attach # [1]
tmux attach
this command will simply attach back to tmux if you are ever disconnected
If you ever run long running tasks on a remote machine by sshing into this you
should be doing it inside tmux, or something like tmux so that you do not loose
your work.
attach to a specific session # [2]
If you have multiple sessions running you can select the session that you want
to attach to by passing -t <name-of-session>.
tmux attach -t scratch
How I navigate tmux in 2021 [3]
for more information on how I navigate tmux, check out this full post
Also check out the full YouTube
tmux-playlist [4]
to see all of the videos i...
tmux ls
https://youtu.be/LY41GLn_DGg
tmux ls will list the sessions that you have running within the tmux server if
tmux is currently running. This is handy to combine with commands such as attach.
tmux ls
tmux attach [1]
How I navigate tmux in 2021 [2]
for more information on how I navigate tmux, check out this full post
Also check out the full YouTube
tmux-playlist [3]
to see all of the videos in this series.
References:
[1]: /tmux-attach/
[2]: /tmux-nav-2021/
[3]: https://www.youtube.com/playlist?list=PLTRNG6WIHETB4reAxbWza3CZeP9KL6Bkr
tmux command line
https://youtu.be/SNu-4IrkjAs
So far we have covered a lot of tmux commands and how they map to keybindings
but these same commands can be executed at the command line.
From the command line # [1]
Let’s make a popup that displays our git [2] status for 5s or until we close it
manually. We can run the following command at the command line, in a split.
tmux display-popup -E -d '#{pane_current_path}' 'git status && sleep 5'
From the tmux command line # [3]
Or we can open the tmux command line and run it from tmux’s built in command
line, which is very similar to bim EX mode. By default the tmux command line
can be opened with prefix+[.
display-popup -E -d '#{pane_current_path}' 'git status && sleep 5'
🗒️ note that the tmux command is called by default when inside of tmux.
Make it a keybinding # [4]
Finally we can make it a keybinding by adding a bind command ahead of our tmux
command, then we can execute this in the tmux command line or add it to our
~/.tmux.conf.
bind s displ...
tmux copy-mode
https://youtu.be/-ypY_-VmBKk
tmux copy-mode is a tmux mode that lets you scroll, search, copy, and jump your
way through a pane. There are a ton of keybindings for copy-mode, the main
ones you will need to know are / for searching down ? for searching up, n
for next item, space for starting a selection, and enter to copy the
selection. Arrow keys will be used for navigation unless you have specified vi mode, then it will be hjkl.
Default keybinding to get into copy mode is prefix+[.
bind-key [ copy-mode
If you are a vim user you will likely want to use vi style keys, add this to
your ~/.tmux.conf file to enable vi mode.
setw -g mode-keys vi
full list of copy-mode keybindings from the man page.
Command vi emacs
append-selection
append-selection-and-cancel A
back-to-indentation ^ M-m
begin-selection Space C-Space
bottom-line L
cancel q Escape
clear-selection Escape C-g
copy-end-of-line [<prefix>] D C-k
copy-line [<prefix>]
copy-pipe [<command>] [<prefix>]
copy-pipe-no...
tmux join-pane
https://youtu.be/Vm5rRtcVXLw
Join-pane allows you to join panes that you have broken away from your window,
or created in a different window to the window you want it in. As far as I
know there is not a default keybinding for it.
Before you can join a pane you must first have a pane marked to join. Once you
mark a pane, go back to the window you want to join it to and join-pane.
My keybindings, you must add this to your ~/.tmux.conf file to use them.
# Mark and swap panes
#――――――――――――――――――――――――――――――――――――――――――――
bind -n M-m select-pane -m # mark
bind -n M-M select-pane -M # unmark
bind -n M-< join-pane
How I navigate tmux in 2021 [1]
for more information on how I navigate tmux, check out this full post
Also check out the full YouTube
tmux-playlist [2]
to see all of the videos in this series.
References:
[1]: /tmux-nav-2021/
[2]: https://www.youtube.com/playlist?list=PLTRNG6WIHETB4reAxbWza3CZeP9KL6Bkr
tmux break-pane
https://youtu.be/ICL609F2xnc
Break-pane is a handy tmux command when your layout gets too cramped and you
want to just move a split into its own window. Calling break-pane does
exactly that, it creates a new-window for you and moves your currently
selected split into that window
Default key binding for break-pane
bind-key ! break-pane
How I navigate tmux in 2021 [1]
for more information on how I navigate tmux, check out this full post
References:
[1]: /tmux-nav-2021/
tmux zoom
https://youtu.be/Rn6mOarCQ-Y
Zooming into the current split in tmux is a valuable tool to give yourself some
screen real estate. These days I am almost always presenting, streaming, or
pairing up with a co-worker over a video call. Since I am always sharing my
screen I am generally zoomed in to a level that is just a bit uncomfortable, so
anytime I make a split it is really uncomfortable, being able to zoom into the
split I am focused on is a big help, and also help anyone watching follow where
I am currently working.
Default key bindings for zooming the current split
bind-key z resize-pane -Z
I have rebound this to match the default binding with mod+z rather so that I
get that single keystroke experience.
bind -n M-z resize-pane -Z
How I navigate tmux in 2021 [1]
for more information on how I navigate tmux, check out this full post
References:
[1]: /tmux-nav-2021/
tmux new-window
https://youtu.be/YRPZBv-iYyE
New window as it sounds makes new windows in tmux. Windows are kind of like
tabs. They are another screen within your sessions that you can name and make
new panes in.
Default key bindings for creating and navigating windows in tmux.
bind-key c new-window
bind-key p previous-window
bind-key n next-window
As always I have rebound these keys because I generally prefer a single
keystroke over the prefix plus keybinding approach that tmux gives by default.
#――windows――――――――――――――――――――――――――――――――――――――
bind -n M-c new-window -c '#{pane_current_path}'
bind -n M-p previous-window
bind -n M-n next-window
When I started using tmux I did almost everything in one giant session with
many panes and windows. It became a nightmare to manage and quickly get
between two sets work efficiently. This year I leaned in on sessions quite
heavily. Checkout this 👇 post to see that workflow in depth.
How I navigate tmux in 2021 [1]
for more information on how I navigate ...
tmux slect-pane
https://youtu.be/CPZJZjN9YTY
These are my MOST often used keybindings that I use in tmux. They allow me to
jump between splits with ease with a vim style layout. I can hold mod and jump
between panes with a familiar arrow key.
bind -n M-h select-pane -L
bind -n M-l select-pane -R
bind -n M-k select-pane -U
bind -n M-j select-pane -D
How I navigate tmux in 2021 [1]
for more information on how I navigate tmux, check out this full post
References:
[1]: /tmux-nav-2021/