Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TMUX using HJKL to navigate panes

Tags:

tmux

Standard TMUX is set to use ctrl-b + [up, down, left, right] when navigating between panes.

I would like to make it so that I can use ctrl-b (or the prefix of my choice) + [h,j,k,l].

I thought I had done this with the following vi key in my ~/.tmux.conf settings:

set -g status-keys vi setw -g mode-keys vi 

Yet this didn't seem to change anything (at least not what I was looking for). How can I get this to work. And yes my .tmux.conf is working properly. I can provide more info if needed.

Update:

Here is my full .tmux.conf after trying to get it to work:

set -g status-keys vi setw -g mode-keys vi  set -g prefix C-a unbind C-b bind C-a send-prefix   # smart pane switching with awareness of vim splits bind h select-pane -L bind j select-pane -D bind k select-pane -U bind l select-pane -R 

Alternatively, I have tried using this w/ vim-tmux-navigator Vim plugin:

# smart pane switching with awareness of vim splits bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-h) || tmux select-pane -L" bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-j) || tmux select-pane -D" bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-k) || tmux select-pane -U" bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-l) || tmux select-pane -R" bind -n C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys 'C-\\') || tmux select-pane -l" 

source

Which also doesn't work either. I am a bit stumped.

like image 510
ApathyBear Avatar asked Jun 08 '15 21:06

ApathyBear


People also ask

How do you navigate panes in tmux?

Tmux uses the keybinding 'Prefix' followed by 'Ctrl+o' to cycle around the panes. When you use this key-binding for the first time, it moves the pane in one position clockwise.

How do I switch between tmux Windows?

Ctrl+b, let go of Ctrl, Letf / Right / Up / Down will switch active panes.

What are panes in tmux?

A tmux pane is the entity that we actually use to run commands, scripts, and processes, such as ssh, backup, vim, htop, and what have you. Technically, they are pseudoterminals encapsulating shells, like Zsh or Bash. In other words, they are terminals within a terminal.

How do I resize a tmux pane?

In order to resize tmux panes, you first hit your tmux prefix ( ctrl + b is the default one. Mine is ctrl + a .), and then the colon key : . This brings up a tmux command mode prompt at the bottom of your screen. All done!


1 Answers

You can do this as follows:

bind h select-pane -L bind j select-pane -D bind k select-pane -U bind l select-pane -R 

Note that mode-keys refers to using vi-like navigation within a buffer and status-keys refers to using vi-like editing within the status bar, but neither refers to switching between panes.

like image 175
Micah Smith Avatar answered Sep 23 '22 11:09

Micah Smith