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
<<<Tab> = <C-I> and <Esc> = <C-[> |
Do you know the "g/" and "g?" commands? >>
Additional Notes
|