Patrick
Patrick

Reputation: 4377

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

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.

Upvotes: 9

Views: 2189

Answers (2)

crenate
crenate

Reputation: 3482

You can also use the old trick to map the Caps Lock to ESC:

xmodmap -e 'clear Lock'
xmodmap -e 'keycode 0x42 = Escape'

Which basically resembles how keyboards used to work once.

Upvotes: 2

Dennis Williamson
Dennis Williamson

Reputation: 360103

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.

Upvotes: 2

Related Questions