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.

  • You can use Ctrl-R and Ctrl-S to search backwards/forward, or Ctrl-A, Ctrl-E, Alt-F, Alt-N for faster movement. – choroba Dec 9 '16 at 16:37
  • Also, you can change the command to o=-a script.sh $o -other -options and only change the value of $o. – choroba Dec 9 '16 at 16:39
  • You replace specific parts of a previous command with carets. echo "Hello" will print Hello afterwards you can do ^Hello^World^to replace Hello with Worldand now the command will be echo "World" You can use that to switch command line options. – ThomasFrederiksen Dec 9 '16 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.