Ctrl+C copies instead of interrupting, or Ctrl+V and Ctrl+A never reach the host
Some terminal programs keep Ctrl+C, Ctrl+V or Ctrl+A for copy, paste and select. Then the key never reaches the host. How to tell, and the keys to use instead.
In a terminal, Ctrl+C normally sends a control character (^C, byte 3) to the host, and the host's terminal driver turns it into an interrupt for the running program. Ctrl+V, Ctrl+A and the other Ctrl+letter keys send their own control characters, which shells and editors use. If the terminal program on your side uses one of those keys for itself, the host never sees it.
Why the key is taken
Some terminal programs use Ctrl+C, Ctrl+V or Ctrl+A for copy, paste and select all. Two examples from their documentation:
- Windows Terminal binds Ctrl+C to copy, and its documentation says that if no text is selected, the key chord is sent directly to the terminal. So Ctrl+C interrupts only when nothing is selected. Ctrl+V is bound to paste by default. Ctrl+Shift+C and Ctrl+Shift+V are also bound to copy and paste.
- IBM Host On-Demand has default shortcut keys Ctrl+C (copy), Ctrl+V (paste), Ctrl+X (cut) and Ctrl+A (select all), but removes them in VT sessions so that Ctrl key values are sent to the host there.
Other programs may have a setting for this; look in their keyboard or key mapping options.
In this app, Ctrl+V on a hardware keyboard always pastes and cannot be remapped, and Ctrl+C copies when text is selected and otherwise goes to the host in a VT session; see What the keyboard sends in a VT session.
Check what reaches the host
On the host, run:
cat -v
Press the key. If cat -v shows ^C, ^V or ^A, the key reached the host and the problem is on the host side: see Keys and key codes. If nothing appears, your terminal program kept the key. Press Ctrl+D on an empty line, or Ctrl+C if it gets through, to leave cat.
stty -a on the host lists which control characters the terminal driver uses: intr = ^C is the interrupt key.
Ways round it
- Clear the selection before pressing Ctrl+C, in a terminal that only copies when text is selected.
- Use the terminal's other copy and paste keys (for example Ctrl+Shift+C and Ctrl+Shift+V in Windows Terminal) and turn off the plain Ctrl bindings, or change them, in the terminal's settings.
- In tmux, the default prefix is Ctrl+B; if Ctrl+A is your prefix and the terminal takes it, choose another prefix with
set -g prefix.
Related
- Keys and key codes
- Ctrl+Space not working over SSH or in tmux: the NUL byte and how to test it
- Escape sequences
- App guide: What the keyboard sends in a VT session
- App guide: Copy, paste and select