Sometimes after starting a terminal process I need to use Ctrl + \ to stop it. Sometimes I can use Ctrl + C but sometimes this is not sufficient and therefore Ctrl + \ is necessary.

How can I enter Ctrl + \ from within tmux? If I press Ctrl + \ that seems to be a tmux shortcut key that takes me to a special tmux screen like this:

enter image description here

rather than sending Ctrl + \ to stdout for the current tmux pane.

I'm using Ubuntu 20.04 and here is my tmux version:

tmux/focal-updates,now 3.0a-2ubuntu0.3 amd64 [installed]

I'm sshing into an AWS EC2 instance if that matters. Here is my ~/.tmux.conf, perhaps I need to make a change here but I'm not sure what to change:

# Change prefix to <Ctrl+a>
unbind C-b
set -g prefix C-b

# Force tmux to send <Ctrl+a> signal to program if you do `<Ctrl+a> a`,
# so I can still go to start of line
bind a send-prefix

# Set default shell
set-option -g default-shell /bin/bash

# UTF is great, let us use that
#set -g utf8
#set-window-option -g utf8 on

#Allows 256 colors in tmux
set -g default-terminal "screen-256color"

# 0 is too far from ` 😉
# set -g base-index 1
# setw -g pane-base-index 1

# don't rename windows automatically
set-option -g allow-rename off

set -g status-keys vi
set -g history-limit 10000

setw -g mode-keys vi
setw -g monitor-activity on

# quickly switch between sessions with prefix+q
bind-key q choose-tree

# Split panes vertically and horizontally
bind-key v split-window -h
bind-key s split-window -v

bind-key J resize-pane -D 5
bind-key K resize-pane -U 5
bind-key H resize-pane -L 5
bind-key L resize-pane -R 5

bind-key M-j resize-pane -D
bind-key M-k resize-pane -U
bind-key M-h resize-pane -L
bind-key M-l resize-pane -R

# Vim style pane selection
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# 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"

# Use Alt-vim keys without prefix key to switch panes.
# M stands for the Meta key in iTerm.
# -n stands for window-name
bind -n M-h select-pane -L
bind -n M-j select-pane -D
bind -n M-k select-pane -U
bind -n M-l select-pane -R

# Use Alt-arrow keys without prefix key to switch panes
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

# Shift arrow to switch windows
bind -n S-Left  previous-window
bind -n S-Right next-window

# No delay for escape key press
set -sg escape-time 0

#  Reload tmux config
bind r source-file ~/.tmux.conf \; display "Reloaded!"


# panes
set -g pane-border-fg black
set -g pane-active-border-fg brightred

# messaging
set -g message-fg black
set -g message-bg yellow
set -g message-command-fg blue
set -g message-command-bg black

#window mode
setw -g mode-bg colour6
setw -g mode-fg colour0

# window status
setw -g window-status-format " #F#I:#W#F "
setw -g window-status-current-format " #F#I:#W#F "
setw -g window-status-format "#[fg=magenta]#[bg=black] #I #[bg=cyan]#[fg=colour8] #W "
setw -g window-status-current-format "#[bg=brightmagenta]#[fg=colour8] #I #[fg=colour8]#[bg=colour14] W "
setw -g window-status-current-bg colour0
setw -g window-status-current-fg colour11
setw -g window-status-current-attr dim
setw -g window-status-bg green
setw -g window-status-fg black
setw -g window-status-attr reverse

# Info on left (I don't have a session display for now)
set -g status-left ''

# loud or quiet?
set-option -g visual-activity off
set-option -g visual-bell off
set-option -g visual-silence off
set-window-option -g monitor-activity off
set-option -g bell-action none

set -g default-terminal "screen-256color"

# The modes {
setw -g clock-mode-colour colour135
setw -g mode-attr bold
setw -g mode-fg colour196
setw -g mode-bg colour238

# }
# The panes {

set -g pane-border-bg colour235
set -g pane-border-fg colour238
set -g pane-active-border-bg colour236
set -g pane-active-border-fg colour51

# }
# The statusbar {

# status line
set -g status-justify left
set -g status-interval 2
set -g status-bg colour234
set -g status-fg colour137
set -g status-attr dim
set -g status-left ''
set -g status-right ' #S #[fg=colour233,bg=colour243,bold] %a %b %d, %Y #[fg=colour233,bg=colour245,bold] %-I:%M %p '
set -g status-right-length 50
set -g status-left-length 20

setw -g window-status-current-fg colour81
setw -g window-status-current-bg colour238
setw -g window-status-current-attr bold
setw -g window-status-current-format ' #I#[fg=colour250]:#[fg=colour255]#W#[fg=colour50]#F '

setw -g window-status-fg colour138
setw -g window-status-bg colour235
setw -g window-status-attr none
setw -g window-status-format ' #I#[fg=colour237]:#[fg=colour250]#W#[fg=colour244]#F '

setw -g window-status-bell-attr bold
setw -g window-status-bell-fg colour255
setw -g window-status-bell-bg colour1

# }
# The messages {

set -g message-attr bold
set -g message-fg colour232
set -g message-bg colour166

# }

# Rearrange windows (move current window Ctrl + Shift + Direction[arrow key])
bind-key -n C-S-Left swap-window -t -1
bind-key -n C-S-Right swap-window -t +1

# Enable mouse control (clickable windows, panes, resizable panes)
set -g mouse on

--- Edit ---

Response to questions from K. Maciorowski in the comments section:

  1. The .tmux.conf I've posted above is from the EC2 instance.

  2. I'm entering a tmux session only after sshing into the EC2 instance, i.e. I'm not using tmux on my local machine.

  3. On the EC2 instance, in the /etc directory, there is no file named tmux.conf or .tmux.conf. The only tmux config file seems to be the one posted above, which is at ~/.tmux.conf

--- Edit2 --

Additional response to questions from K. Maciorowski in the comments section:

  1. Yes, the problem happens when I start a new tmux session.

  2. $ tmux list-keys -T root | grep -F 'C-' bind-key -T root C-\ run-shell "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys 'C-\') || tmux select-pane -l"

  3. If I do:

    tmux unbind-key -T root 'C-'

before entering a tmux session then that does solve the problem, Ctrl + \ then does what it normally would.

Based on this I commented out the line

bind -n C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys 'C-\\') || tmux select-pane -l"

in ~/.tmux.conf then rebooted and that seems to have solved the problem, if you post your diagnostics steps as an answer I will accept.

  • When sshing, one may use tmux locally or on the remote side (or in both places). Please confirm the .tmux.conf you posted is from the machine your tmux runs and you don't use tmux on the other machine. Does /etc/tmux.conf exist on the relevant machine? What is the content? Jun 18, 2022 at 7:58
  • @KamilMaciorowski posted additional clarification as you've instructed in the post
    – cdahms
    Jun 18, 2022 at 14:38
  • Does the problem appear when you start a tmux server anew? What is the output of tmux list-keys -T root | grep -F 'C-\'? Does tmux unbind-key -T root 'C-\' help at least temporarily? Jun 19, 2022 at 9:04
  • @KamilMaciorowski posted additional info per you're further questions
    – cdahms
    Jun 21, 2022 at 17:08

1 Answer 1


in ~/.tmux.conf commenting out the line:

bind -n C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys 'C-\\') || tmux select-pane -l"

then killing the tmux session and starting a new one (or rebooting) makes Ctrl + \ work as expected within tmux

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.