How can you execute a command again listed in the
:history
option in vim. There are numbers shown. Is the only way to copy the command by hand, then re-enter it? Or is there something like in shell script.
Ctrl+R: Recall the last command matching the characters you provide. Press this shortcut and start typing to search your bash history for a command. Ctrl+O: Run the command you found with Ctrl+R. Ctrl+G: Leave the history searching mode without running a command.
The " @: " command repeats the last command-line change (a command invoked with " : ", for example :s/old/new/ ). You can move the cursor before using either of the repeat commands. Suppose you press dd to delete a line. Next, you might move the cursor, then press 5.
Press Ctrl+F in command mode to open the command history window. Then, you can use / , ? , and other search commands. Press Enter to execute a command from the history.
For example, most of us know that we can press Ctrl-p (or the Up-Arrow key) to recall the last command so that we can modify it and press Enter to execute it.
:history
is only there for you to look at it.
To re-execute a previous command, you have two options:
Use <Up>
and <Down>
at the command prompt:
:m10
(do stuff)
:<Up>
Use the "command-line window":
You can call it with q:
and navigate with search and use the beautiful normal mode commands we all love.
Position the cursor on a line and hit <CR>
to re-execute the command.
Edit a command and hit <CR>
to execute the new command.
You can quit the command-line window with :q
.
See :help cmdline-window
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With