Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash vi mode - bind "C-c" to escape from insert mode

Tags:

bash

vim

vi

I just discover the magic of using vi style in bash. Immediately, I'm trying to use C-c to escape from insert mode (into what's called movement mode) as I'm used to C-c to escape to command mode in vim.

I searched around and found the command to rebind key in bash:

"bind -m vi-insert C-c:vi-movement-mode"

Then, I used "bind -P" to check the binding status and it showed:

"..."
"vi-movement-mode can be found on "\C-c", "\e"."

However, when I tried to escape from insert mode, it cleared the entire line instead (the default behavior), instead of escape to movement mode... Any thought how can I use C-c to escape from insert mode?

Thanks in advance.

like image 486
Patrick Avatar asked Jun 27 '10 05:06

Patrick


1 Answers

You can rebind the interrupt key:

stty intr ^X

Now to interrupt something that's executing you'll have to press Ctrl-x. I don't know if changing this might have other side effects.

The reason that vim can do that is that it traps the Ctrl-c interrupt.

like image 194
Dennis Williamson Avatar answered Oct 05 '22 07:10

Dennis Williamson