I'm using Bash Vi mode (aka set -o vi). Still I miss the Ctrl-A shortcut from Emacs mode, which is very handy. Many times I'm retrieving the last command and append an echo to the beginning of the line in order to save it to a file.

Is there a convenient way to jump to the start of the line while in insert mode?

And by convenient I mean that it's accessible by two sensible buttons shortcut. So Esc,I is not good enough, because Esc is too far, and Ctrl+[,I is not good because I need to type three consecutive letters, not sleek enough.

• If Esc is too far, why are you using vi mode at all? Why don't you stick with emacs mode? – glenn jackman Feb 15 '11 at 14:04
• If you are a vi fan, I highly suggest binding your Caps Lock key to ESC. – mattdm Feb 15 '11 at 14:30
• @mattdm, by who? by X? by bash? Unfortunately, I already have Capslock bound to the keyboard layout switch, and it's hard to find another reachable key... – Elazar Leibovich Feb 15 '11 at 18:41
• Yeah, by X. If you use the keyboard layout (altgr?) switch a lot, that might be unavoidable. I use the "menu" key for that, but I really use it only infrequently. – mattdm Feb 15 '11 at 18:48

Press the Home key if it's not too far. Or bind Ctrl+A:

set -o vi
bind '\C-a:beginning-of-line'

• I didn't want to walk down the slippery bind slope, since eventually you end up with a .emacs file more complex than the emacs source code, but it's certainly a viable option. – Elazar Leibovich Feb 15 '11 at 9:05

Many times I'm retrieving the last command and append an echo to the beginning of the line in order to save it to a file.

An alternative is:

echo !!

• Yeah, I know that. But sometimes I don't remember which one of the last 3 commands it was, so I want to see them first on the screen, or change a few parameters. Thanks. – Elazar Leibovich Feb 15 '11 at 9:20
• Then do history, then echo !nnn where nnn is the history number. If you know it was the 2nd last command, then echo !-2 also works – glenn jackman Feb 15 '11 at 14:05
• @glenn, as I said: (1) I don't remember the exact number, (2) sometimes I need to edit the line lightly. – Elazar Leibovich Feb 15 '11 at 18:41