Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Moving between tmux panes à la Spacemacs

Moving between tmux panes à la Spacemacs

tl;dr

Along with Spacemacs I work with a tmux session with all my projects opened, usually a single project window consists in at least two panes, one for the server and one for the tests.

In Spacemacs you move to window 2 with SPC-2. It's pretty useful, especially when you have multiple files opened.

In tmux I used to move around using C-a UP if for example I wanted to go to the pane above the current one, needless to say this feels awkward when you switch from one program to the other, so I tweaked the configuration a bit until I got the same behaviour in both.

The code

In my .zshrc

tmux-select-pane-1() { tmux select-pane -t '1' }
zle -N tmux-select-pane-1
bindkey " 1" tmux-select-pane-1

So whenever I type SPC-1 in rapid succession I move to pane 1.

To avoid having pane numbers starting from 0 I have this in my .tmux.conf

setw -g pane-base-index 1

I've found it useful to have the pane number in my RPS1, so I know where to switch, use this:

echo $(tmux display-message -p '#P')

Drawbacks

You have to be careful when you write a space followed by a number (it happens in my workflow as I use SCM breeze), but it's a minor annoyance and I think over time I'll get used to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.