Ctrl+Space not working over SSH or in tmux: the NUL byte and how to test it
Ctrl+Space sends one NUL byte (0x00), the same as Ctrl+@. Test with od -c on the host to see if it arrives; old Windows ssh.exe and OS shortcuts can drop it.
In a terminal, Ctrl+Space sends a single NUL byte (0x00). Ctrl+@ sends the same byte; on a US layout that is Ctrl+Shift+2. The host cannot tell the two apart, which is why tmux treats C-Space and C-@ as one key.
Programs that use the byte include tmux, where it can be set as the prefix key and begins a selection in copy mode with emacs keys, and Bash's readline, where C-@ is set-mark. When Ctrl+Space "does nothing", the first question is whether the byte reaches the host at all.
Test whether the byte arrives
On the host, run:
od -c
Press Ctrl+Space, then Enter, then Ctrl+D. If the byte arrived, the terminal echoes ^@ while you type, and od prints it as \0:
0000000 \0 \n
0000002
If od shows only \n, the byte was lost before it reached the host program. Run the same test in a local shell on your own computer, without SSH, to see whether the terminal sends it at all. cat -v works too: it prints ^@ for the byte.
Where the byte gets lost
- Your computer uses the shortcut. On a Mac with more than one input source, Control-Space switches input sources, so the terminal never sees it. Change or turn off that shortcut in the keyboard settings, or use Ctrl+@ instead.
- The terminal program does not send it, or maps the chord to its own action. The local test above shows this. Check the program's key settings.
- The Windows OpenSSH client drops it. Older versions of the
ssh.exefrom the Win32-OpenSSH project did not pass Ctrl+Space or Ctrl+@ to the server, even when the terminal sent it. The fix was merged in March 2022 and is in the project's 8.9.1.0 release and later. Thessh.exethat comes with Windows can be older; runssh -Vto see the version, and install a newer release if it is below 8.9. - A multiplexer in the middle has its own binding. In tmux copy mode with emacs keys,
C-Spacestarts a selection instead of reaching the program in the pane.
Use it as the tmux prefix
Once the test shows \0, tmux can use the key as its prefix. In ~/.tmux.conf:
unbind C-b
set -g prefix C-Space
bind C-Space send-prefix
Reload with tmux source-file ~/.tmux.conf. The last line lets you press the prefix twice to send one Ctrl+Space to the program inside tmux. If the byte cannot be made to arrive from one of your devices, pick another prefix for that setup, for example set -g prefix C-a.
Related
- Keys and key codes
- Shift+Enter or Ctrl+Enter acts like Enter in a terminal: why, and how to fix it
- tmux "sessions should be nested with care, unset $TMUX to force"
- Scroll back and search history in tmux
- Shell and tmux basics
- Ctrl+C copies instead of interrupting, or Ctrl+V and Ctrl+A never reach the host
- Change the tmux prefix key from Ctrl+B to Ctrl+A or another key
Sources
- tmux wiki: Modifier Keys (C-@ is also C-Space; how to test a key)
- tmux(1) manual: prefix, send-prefix, copy mode begin-selection
- ascii(7): NUL is code 0
- readline(3): set-mark (C-@)
- od(1): -c shows bytes as characters and escapes
- Win32-OpenSSH issue 1842: Control+Space not sent
- Win32-OpenSSH pull request 569: fix for Ctrl+Space not being sent
- Mac User Guide: Write in another language on Mac (Control-Space switches input sources)