Vim logo vim online Vim Book Ad

 Tip #170: Repeating a sequence of commands without defining a macro

 tip karma   Rating 36/24, Viewed by 1205 

created:   November 27, 2001 23:45      complexity:   intermediate
author:   Stanislav Sitar      as of Vim:   6.0

Imagine.

You have just finished a complicated modification of a file,
involving numerous replace commands :%s/xxx/yyyy/g,
and other ex commands.

Then you realize, you have done it a little bit wrong,
and you have to begin all the operation again,
just to change one replace string, or do one more operation
"somewhere 10 commands ago".

Or you realize, you will have to do the same stuff tomorrow
with another file.

or you realize, you want to perform the same sequence
of commands, you have typed a few days ago

You should have made it a macro (normal command q),
but you haven't.

Nothing is lost yet.

You go to the command line (by typing :)
and press Ctrl+F.
(Ctrl+F in other modes scrolls the screen)

You get a temporary window, listing the history of command line.
It is possible to yank appropriate lines here,
make a new file called $VIMRUNTIME/macros/something.vim
put those lines here, edit them and save

see
:help cedit


Then you can call the macro using
:source something.vim


You might want to set variable 'history' to a higher
number then default in your vimrc file
like
:set history=300
see
:help history
:help vimrc


 rate this tip  Life Changing Helpful Unfulfilling 

<<<Tab> = <C-I> and <Esc> = <C-[> | Do you know the "g/" and "g?" commands? >>

Additional Notes

[email protected], December 5, 2001 11:38
You can also bring up the command line history while in Normal mode by typing:

q:

which is just a touch faster than :<Ctrl-F>. (-: (Actually, I didn't even know about Ctrl-F in : mode until I read this tip. Neat!)
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo