24

I am using iTerm2 on a Macbook Pro running MacOS Mojave.

In certain situations, such as when doing a git add -p, pressing return ends up printing ^M instead of performing the action.

Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? ^M

Actual demo output

That means I am unable to take any action on a hunk as I cannot submit any of the given choices.


I though this could be because of how git handles returns, so I modified the core.autocrlf config but none of its valid values cause any change in this behaviour.

Then when trying other methods I relaized that this problem is visible only when using iTerm and NOT the Terminal app despite using zsh in both.


What configuration should I modify to allow for the return key to behave normally in this case?

2
  • 1
    By any chance... do you press accidentally CTRL+V before hitting the ENTER key? In the standard zsh keybindings CTRL+V (^V) this is bound to quoted-insert, i.e. the next pressed key is inserted literally. ^M for ENTER, ^[ for ESC and so on.
    – mpy
    Commented Feb 7, 2019 at 17:37
  • @mpy Did not know about that. Tried carefully again, same behaviour observed
    – Sinstein
    Commented Feb 8, 2019 at 10:33

2 Answers 2

36

This problem occurs because of the odd or old terminal line settings. The stty tool on Unix can help you reset them.

I have had the same issue on Iterm2 on Mac and got it fixed using it.

stty sane

This command fixes terminal oddities by resetting them to reasonable defaults.

Look at man stty or this good read for more info. http://www.peachpit.com/articles/article.aspx?p=659655&seqNum=13

1
  • Just had this using standard ssh user@host and the stty sane worked perfectly. Thank you so much!
    – Matt Ray
    Commented Sep 4, 2022 at 15:16
4

I restarted iterm tab and it got fixed.

You must log in to answer this question.

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