23

I'm using iTerm2 on Mac OSX (10.10.5).

Recently I encounter something very strange: after using iTerm2 for a while, Ctrl-C would stop working. Initially it was fine. Only after a certain period of usage. The terminal would print out ^C as if it were a normal key press.

I have no idea how this could be reproduced.

3
  • 1
    I'm seeing the same thing. Any luck wih this problem? Nov 16, 2017 at 21:11
  • 2
    I'm starting to think that this is a zsh problem.
    – lang2
    Feb 1, 2018 at 1:59
  • Also see this SO question. I spent a long time trying to understand why I couldn't receive control-c from iTerm2... at first I thought it was a python problem... only later realizing that control-c under iTerm2 seems to be broken... other terminals (such as hyper, kitty done have this problem) Sep 11, 2021 at 22:07

4 Answers 4

9

One of the possible causes for this is that you've used trap to set the INT signal to something else.

If you reset the trap(ed function) on INT to default, this problem should go away1. You can do that by doing this:

trap - INT
trap

One other way to fix this, although "hacky", is to add something like the following to your .zshrc or .bashrc:

function reset_trap {
  # Hacky hack because of <function/script-that-sets-trap-INT>
  trap - INT
}

autoload -Uz add-zsh-hook
add-zsh-hook preexec reset_trap

1 At least, that/this worked for me!

8

I'm posting a work around here as it might benefit some people. I will not accept it myself though.

When this happens, kill the running process in the current tab, probably from a different tab/shell. Then in the original tab, execute reset and things will get back to normal.

Still don't know why.

2
1

This feels like the most visible question around this so I wanted to share my solution to this.

I had this issue to but specifically only when using a hotkey window. Mine was a result of using KarabinerElements to remap keys. I was using a pre-built rule called PC-Style Copy/Paste/Cut which was re-mapping Ctrl+C to Command+C, that wasn't always working.

I was seeing different behaviour in the Hotkey window to a regular iTerm2 window, and the reason is that these rules have exclusions for iTerm2 using the following app id "^com\\.googlecode\\.iterm2$". However it seems that when the hotkey window gets focus it doesn't report it as having focus (verified using https://apple.stackexchange.com/a/170699/514960). This meant that I could Ctrl+C in an iTerm2 window fine, and I could in the hotkey window (as long as iTerm2 was the last thing that had focus).

If any other app had focus, KarabinerElements couldn't detect it, and therefore the override was still kicking in. To fix it I added a custom keybinding in iTerm2 such that when it sees Left_Command+C it will send the HexCode 0x03 (obtained from https://www.physics.udel.edu/~watson/scen103/ascii.html). This now works regardless of whether KarabinerElements is remapping the key or not. I had the same issue with Ctrl+R and probably some more I've not yet discovered!

0

This happened to me and it was because I had set up CTRL+C as a Global shortcut in Zoom. So, it only was an issue when I was in a Zoom meeting.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .