edit: I mistakenly said at first "ctrl-f" where it is in fact "ctrl-r" ... (which I use multiple times a day). I edited the correct commands now ...
Not the method you asked, but probably good for what you seem to need to do (ie, find a previous line in history and edit it before entering/executing it again):
# in bash
[Ctrl]+r Foo
# This recalls the previous history line containing Foo, in edit mode.
# You can then:
# [Enter] to execute it "as is", and returns to prompt.
# -or- [Ctrl]+o executes it "as is" + presents the following
# history line, ready to be executed
# -or- <Leftarrow> or <Rightarrow> makes that line the current one
# and you can then edit it before executing it (what OP asked for)
# -or- [Ctrl]+c to return to the prompt without executing
# the currently displayed command line.
# -or- another [Ctrl]+r search the previous occurrence of Foo
That way no need to do history and figure out which history number you needed to edit and another combination to actually retrieve and edit it: [Ctrl]+r Something will find the previous line(s) containing Something for you and present it in edit mode. It is much faster, in general.
Ctrl-o (instead of enter) is especially usefull if you often need to edit 1 command and follow it by a repeat sequence of commands
And nice bonus: this ctrl-r, etc : is often available in other programs (ex: mariadb-server cli [ usefull to retrieve the last 'use' command] , and probably many others). It is probably based on (maybe offered by, or at least using) the "readline" mechanism, but I do not know the details...