4

In zsh with vi bindings, I want to leave insert mode not only using Esc but also using Ctrl-c. I tried this as suggested in another answer.

bindkey -M viins '^C' vi-cmd-mode

Pressing Ctrl-c still just creates a new prompt below the last one. How can I bind to Ctrl-c in insert mode in zle?

5
  • nitpick: Zsh has no vim` bindings, it has vi bindings. There is nothing vim-specific (as far as I know) about them.
    – Celada
    Commented Jun 12, 2016 at 15:30
  • @Celada Thanks for the correction. Would be cool to have vim functionality though.
    – danijar
    Commented Jun 12, 2016 at 15:34
  • If you like. Personally I learned on some sort of SysV version of vi and only know standard vi. The only reason I use vim today is because it's the most conveniently available vi variant that isn't totally broken by Unicode and such; but I have to use vim's compatible mode because otherwise it greatly breaks my expectations.
    – Celada
    Commented Jun 12, 2016 at 15:38
  • 2
    I'd advise against this; C-c handling is already hilariously complicated, as the shell process is actually reacting to an INT signal that may or may not be blocked depending on what the shell is doing at that moment.
    – thrig
    Commented Jun 12, 2016 at 15:46
  • 1
    @Celada since version 5.0.8 zsh actually does support some vim(-like) features, such as text objects and visual mode.
    – Adaephon
    Commented Jun 13, 2016 at 14:20

1 Answer 1

2

You can try to just remap interrupting to any other key (1):

stty intr \^E
1
  • Works for me. You can do this with a precmd_function() and then undo it with a preexec_function() so that it only effects when you are typing at the prompt.
    – Von
    Commented Apr 20, 2019 at 12:00

You must log in to answer this question.

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