I'm using Bash in "vi mode". What's the hotkey sequence to edit the current command line using an external editor?

Solution 1:

The emacs mode binding executes command edit-and-execute-command. To see which binding executes it in vi mode you can give command:

$ bind -m vi -q edit-and-execute-command
edit-and-execute-command is not bound to any keys.

Easiest would be to add a binding for it

$ bind -m vi-insert '"\C-x\C-e": edit-and-execute-command'

To make it permanent, you can add it to ~/.inputrc as

set keymap vi-insert
"\C-x\C-e": edit-and-execute-command

Solution 2:

The answer

Press ESC to go into vi-command mode, then press v. Bash will start your your chosen $EDITOR. If you haven't chosen one, Bash will start vi (the visual editor).

Explanation

Why does Bash's ESCv start vi?

Because Bash's bashline.c includes the function call:

rl_bind_key_if_unbound_in_map ('v', vi_edit_and_execute_command, vi_movement_keymap);

What is vi_edit_and_execute_command? It's a Bash C function, defined elsewhere in bashline.c.

One aside. I have experimented a bit, and the following is what I now suspect is true. Binding Bash C functions is weird. You can do it from within Bash's source code, but it seems impossible to do so by using the bind builtin at the Bash prompt. And, once you've done it, the bind builtin doesn't seem to even recognize that it's been done.

I thank Glenn Jackman for pointing out that ESCv is the answer, and dualbus and Riviera of Freenode #bash for helping me to figure out the explanation above.