Bash – How to retain cursor position in previous command

bashcommand historyshell

When I iterate over previous commands in bash history, cursor position always jumps at the end of the command. I want some way of remembering current cursor position of last executed command.

This can be useful when trying different command line options for some command. Now I have to press up key and move cursor backwards to where the option was typed to edit it. I want to eliminate this second step if it is possible.

I am using bash, but solutions for other shells are also interesting.

Best Answer

Maybe this is the option you're looking for?

history-preserve-point (Off)
        If  set to On, the history code attempts to place point at the
        same location on each history line retrieved 
        with previous-history or next-history.

To turn it on, add this to your ~/.inputrc:

set history-preserve-point on
Related Question