Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-execute command by :history option in VIM

Tags:

vim

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.

like image 236
Hendrik Avatar asked Aug 26 '13 10:08

Hendrik


People also ask

How do I rerun a command in history?

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.

How do I repeat a previous command in Vim?

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.

How do I find previous commands in Vim?

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.

Which key is used to reuse the previous command?

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.


1 Answers

: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.

like image 172
romainl Avatar answered Oct 04 '22 04:10

romainl