Reputation: 10438
I'm relatively new to tmux and use it just for local development. In some tmux tutorials, a person will list out their tmux sessions in an enumerated list. There is yellow highlight typically. Does anyone know what I'm talking about and how to do it? Secondly, would you say this is best practice? I'm over here with 8 iTerm2 tabs open :(
Here's a screenshot of what I'm looking for:
Upvotes: 127
Views: 101777
Reputation: 95
if you man tmux
you will find a list of tmux options:
PREFIX-( Switch the attached client to the previous session.
PREFIX-) Switch the attached client to the next session.
no need to change your tmux.conf
Upvotes: 7
Reputation: 12639
So many issues on the given solutions:
:switch-client -t #{session_name}
is annoying, because you have to type the full session nameYou can list all sessions, order them and grep the right one that starts with your input name, so in most cases all you have to enter is the first letter of the session name:
bind S command-prompt -p "session abbr:" "run 'tmux switch -t $(tmux ls -F \"##{session_created}:##{session_name}\" | sort -n | grep \':%%\' | head -n 1 | cut -d \':\' -f 2)'"
run
runs a shell commandtmux switch -t
will switch to the session with the same name like the output from the result expressiontmux ls -F "#{session_created}:#{session_name}"
lists all sessions like so: 1687458684:main
session_created
, we can order by age with sort -n
grep ':%%'
(note the :
and our input %%
)head -n 1
will give us only the first matchcut -d ':' -f 2
will return the part after :
, which is our target session name for tmux switch
Just bind it to the same key as your prefix, then you can hit your prefix twice, type a letter and hit enter to jump to another session.
Upvotes: 7
Reputation: 10438
ctrl+b, s
Note ctrl+b is my prefix, your prefix could be something else.
Upvotes: 213
Reputation: 5247
You can also do tmux switch -t <session name or number>
or C-b )
for forward or C-b (
for forward nice ref: https://tmuxcheatsheet.com/
Upvotes: 0
Reputation: 182
A faster switch by name is for example possible with a shell alias. For the zsh it can look as follows:
function tn() (
if [ -n "$1" ]
then
tmux switch -t $1
else
echo "no session name"
fi
)
With tn go
you switch to the tmux session with name go.
Upvotes: 4
Reputation: 2055
Use tmux switch -t [target-session]
if want to switch instant
Upvotes: 11
Reputation: 859
Is PREFIX s
but the real command is choose-tree. Then you can use it to bind to other key for example to 'S'
bind S choose-tree
http://man.openbsd.org/OpenBSD-current/man1/tmux.1#choose-tree
Upvotes: 12
Reputation: 28272
You're looking for C-b (
and C-b )
. You can find this and many more wonderful tips on the tmux cheatsheet.
Upvotes: 62