- Press
q:. This opens a special window in your Vim buffer which lists all previously executed commands, similar to a regular file buffer. - Use the standard Vim movement keys (
j,k,G, etc.) to navigate to the command you wish to re-run. - Press
Enterwhile your cursor is on the line of the desired command. Vim will execute that command and close the history window. - To exit the window without running a command, use
:qorCtrl-C. - Type
:to start a new command line. - Use the Up Arrow (
<Up>) orCtrl-Pto go back through the history of previous commands. - Use the Down Arrow (
<Down>) orCtrl-Nto go forward through the history. - When the desired command appears on the command line, press
Enterto execute it. - Press
q/(for forward search) orq?(for backward search) to open the search history window. - Type your search pattern (e.g.,
s/) and pressEnter. The window will list commands matching that pattern. - Navigate to the command you want to run and press
Enterto execute it. - Type
:@:followed by the number of the history entry you want to execute (e.g.,:@:25to run command number 25).
To re-run a command from your Vim history, you can use the following methods:
1. Using the Command-line Window (
q:)The most common and interactive way is to open the command-line window:
2. Using Command-line History Navigation
You can cycle through your command history directly from the command prompt:
3. Using History Search (
q/ or q?) If you have a long history and want to find a specific command quickly, you can search for it:
4. Running a Specific History Index
You can also run a specific command by its index number if you know it from viewing
:history. This is less common but useful if you need an exact, old command:
No comments:
Post a Comment