brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: tmux new-window -a opens the new window right after the current one

Tmux
~/tips/tip-tmux-new-window-after

tmux new-window -a

Creates a new tmux window directly after the current one instead of at the end.

New windows go to the end of the list by default. With ten windows open, the one I just made for a quick side task lands far away from the one I am working in.

new-window has a flag for position:

tmux new-window -a

The manual says that with -a or -b the new window is inserted at the next index after or before the target window, moving windows up if necessary. So -a puts it right behind the current window and -b right in front of it.

I would bind it to a key in ~/.tmux.conf. Pick a key that is free on your setup, and check with tmux list-keys first:

bind-key N new-window -a -c "#{pane_current_path}"

The -c part starts the shell in the directory of the pane you are in, which suits a side task in the same project. After tmux source-file ~/.tmux.conf, Ctrl-b N creates a window next to the current one and moves the later ones up by one.

The caveat: later windows change their number. If you jump to windows by digit, or a script refers to a window by index, those numbers shift when you insert in the middle. Names hold up better, and -n sets one when you create the window:

tmux new-window -a -n scratch

Further reading: tmux manual (new-window)

More Tmux tips tmux new -d -s report -x 200 -y 50 'top' tmux wait-for build-done set -g allow-passthrough on tmux kill-server Ctrl-b [ All Tmux tips (125) All topics

Link