Macro in Vim is extremely useful to perform tasks that is difficult to finish in normal command line tool (sed
, awk
, perl
, etc.), is there any way to perform that kinds of macro string in command line?
Something like the following:
// execute macro stored in register a 100 times for filenames
vim execute -s "100@a" filenames [filenames2, filenames3, ...]
For those having trouble to execute a number of normal commands (like a macro) and exiting again, it is possible to first define the macro.
vim files* -c "let @l=\"ggOStart\<Esc>GoEnd\<Esc>\" | argdo normal @l | ZZ"
The command will insert "Start" to the beginning of each file starting with files*
and "End" to the end, but an arbitrary macro might be applied.
That way it's possible to define and execute a macro without it being already present. You will have to use and escape double quotes \"
if you want to be using any key-notation such as \<Esc>
mentioned here.
By adding ZZ
to the end, the file is written and closed again. Commands can be concatenated by a |
symbol.
You are almost there:
$ vim file* -c "argdo norm 100@a"
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