How can I bind a key to go to the last panel, or if there are no windows in the last window?

If I work on a widescreen monitor, I like to mainly use two panels and switch between them using Ca Ca

If I work on a square monitor, I will use two windows. I would like to be able to switch between them using Ca Ca without changing tmux.conf .

+7
source share
2 answers

If you always want Ca

  • Switch between panels when the active window has more than one panel, and
  • Switch between windows when the active window has only one panel,

then you can use an if-shell , which counts the number of panels in the active window, to choose between last-pane and last-window :

 bind-key Ca if-shell 'test $(tmux list-panes | wc -l) -gt 1' 'last-pane' 'last-window' 

When switching between wide and square configurations (for example, through break-pane and join-pane ), it will still be “up to you” to rearrange your panels.


In tmux 1.8, if-shell and run-shell format the extension, so you can simply execute the shell command:

 bind-key Ca if-shell 'test #{window_panes} -gt 1' 'last-pane' 'last-window' 
+10
source

I would suggest the following (adjust 80 to distinguish between your two terminal widths)

 if-shell '[ "$COLUMNS" -gt 80 ]' 'bind-key Ca "select-window -t :.+"' 'bind-key Ca "next-window"' 

but I either messed up the syntax or COLUMNS not set in the corresponding tmux environment, since the shell expression above always evaluates to false for me.

+1
source

All Articles