GNU Screen has Ctrl-a,Ctrl-a to switch between the two latest windows.
How to do it in tmux?
GNU Screen has Ctrl-a,Ctrl-a to switch between the two latest windows.
How to do it in tmux?
To do this in tmux, you do
Ctrl-Bl
(that is a lowercase 'L'). This assumes you have left Ctrl-B as your activation key.
If you want to use the same keypresses as screen, then add the following to your ~/.tmux.conf:
set-option -g prefix C-a
bind-key C-a last-window
The first sets Ctrl-A as your activation key, the second says Ctrl-A after activation should go to the last window.
To follow on to fbicknel and Paul:
you can
bind-key C-a last-window
bind-key a send-prefix
which will let you use a screen-like "ctrl-a a" to insert a 'ctrl a'
Paul's answer is correct, but it seems to leave you without a way to type ^A.
See this thread for details, but essentially you can do this to get a C-a (^A) if you need one:
bind-key v send-prefix
Now if you type C-a v you'll get a ^A.
I added:
bind-key l last-window
Into my tmux config file which by default is at ~/.tmux.conf.
Reload tmux, switch windows at least once and press:
ctrl+B (default prefix) + l (lower-case L) works like a charm!
I wanted one that didn't care whether my most previous active thing was a "window" or a "pane". After a bit of work I got it.
add this to your .tmux.conf
set -g focus-events on
bind-key l run-shell "$HOME/bin/tmux-last switch"
set-hook -g pane-focus-out "run-shell 'tmux set-option @last #{pane_id}"
set-hook -g pane-focus-in "run-shell '$HOME/bin/tmux-last in #{@last} #{pane_id}"
And then make this, in our case $HOME/bin/tmux-last:
#!/bin/bash
last="/tmp/tmux-focus-last"
which=$1
if [[ $which == "in" ]]; then
out=$2
in=$3
[[ "$out" == "$in" ]] || echo "$out" > "$last"
elif [[ $which == "switch" ]]; then
to=$(cat "$last")
tmux select-window -t $to
tmux select-pane -t $to
fi
then do
tmux source-file ~/.tmux.conf
Cycle around a few times and then your <tmux-key> + l, should be similar to an "alt-tab" without erroring at you about the fact that you are in a window or pane mode.