0

I'm trying to bind C-h to move to the window on the left. Here is my tmux.conf

set -g default-terminal "xterm-256color" bind -n S-down new-window bind -n C-l next bind -n C-h prev bind q killp unbind C-b set-option -g prefix C-space bind-key C-a send-prefix bind c new-window -a set-option -g history-limit 20000 set -g pane-border-style 'fg=colour1' 

All of these bindings work as expected in normal mode. In copy mode, they all work except C-h, which still functions as backspace and just moves the cursor left. I'm using Vi global bindings so I guess that's why. Is is possible to overwrite this Vi binding? I've tried adding unbind-key C-h first, makes no difference.

The output of tmux list-keys -T copy-mode-vi | grep cursor-left is:

bind-key -T copy-mode-vi C-h send-keys -X cursor-left bind-key -T copy-mode-vi h send-keys -X cursor-left bind-key -T copy-mode-vi BSpace send-keys -X cursor-left bind-key -T copy-mode-vi Left send-keys -X cursor-left 
0

1 Answer 1

1

This tmux command:

unbind-key -T copy-mode-vi C-h 

will remove whatever is bound to C-h in copy-mode-vi. In your case the binding to remove is the default one:

bind-key -T copy-mode-vi C-h send-keys -X cursor-left 

Now your new bind -n C-h prev (whose full form is bind-key -T root C-h previous-window) should work also in copy mode, when mode-keys is set to vi.

You will probably want to put our unbind-key … into your ~/.tmux.conf. Keep in mind the file is parsed when a tmux server starts. To affect your already running server you need to pass the command to tmux by hand (e.g. tmux unbind-key … in a shell inside tmux) or to reload the altered file (e.g. prefix:source-file ~/.tmux.confEnter).

5
  • Great thanks. I first thought you meant I should put unbind-key -T copy-mode-vi C-h in tmux.conf, but that didn't do anything. However, if I run tmux unbind-key -T copy-mode-vi C-h, it works. Is that normal? Note, it needed to be preceded by tmux to work like that in the terminal. Commented Jun 25, 2024 at 14:52
  • @ludog Yes, in tmux.conf; but this file is parsed automatically only when a tmux server starts, changing the file does not change the configuration of the already running tmux server. Commented Jun 25, 2024 at 14:55
  • Hey, yes I know I have to restart for tmux.conf to take effect again, but adding unbind-key -T copy-mode-vi C-h doesn't do anything even when I restart. In fact, running tmux unbind-key -T copy-mode-vi C-h in the terminal is persistent across tmux restarts. Commented Jun 25, 2024 at 15:11
  • @ludog "… is persistent across tmux restarts." – I suspect you're confusing tmux client(s) with the tmux server. Commented Jun 25, 2024 at 15:18
  • Ah yes, you're right, I was confusing those things. I had restarted the tmux session but there was another session still running in another terminal tab so the server did not restart. Exiting all sessions and then relaunching makes the changes take effect. Commented Jun 25, 2024 at 16:47

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.