2

I know I can set bash in vi mode giving set -o vi in the command line. However I find I need vi mode only sometimes and I would like to keep using the normal mode (emacs mode?) and would be lovely to be able to switch to vi mode while I am already typing my new command.

Is there any way to set the vi mode without issuing a CLI command?

For instance it could be switched on by the Terminal application. I use iTerm2 on Mac OS X but I could not find a command to switch mode on the fly.

Any suggestion?

1 Answer 1

0

You would be able to bind the two Readline functions vi-insertion-mode and emacs-editing-mode to a control key combination to toggle between these two input modes on the fly.

The code below first binds vi-insertion-mode to Ctrl+XCtrl+T in emacs-standard mode, and then binds emacs-editing-mode to Ctrl+XCtrl+T (the same key combination, but) in vi-insert mode.

bind -m emacs-standard '"\C-x\C-t": vi-insertion-mode'
bind -m vi-insert      '"\C-x\C-t": emacs-editing-mode'

You may use any control sequence that does not interfere with too many other things and that makes sense to you. The sequence used here is unbound by default.

You must log in to answer this question.

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