Strovent SystemsSign in
Reference

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.exe from 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. The ssh.exe that comes with Windows can be older; run ssh -V to 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-Space starts 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.

Sources

Spotted a mistake? Email [email protected].