Automate vim execution on a file

3

I would like to be able to specify on bash command line set of keys that will vim execute on given file, just the same as I am doing it when manually editing, for instance, hypothetically:

vim myfile +'Gosome footer here<ESC>ggOsome header here<ESC>x'

I know that + executes Ex commands. Is there a way to do that? Using vim only of course.

majkinetor

Posted 2012-12-19T13:08:25.110

Reputation: 510

Answers

4

You're close, just add normal in front of the commands:

vim -c 'normal Gosome footer here' -c 'normal ggOsome header here' -c x myfile

The argument given to -c is evaluated in command-mode, so to execute normal commands you need to prepend normal.

Thor

Posted 2012-12-19T13:08:25.110

Reputation: 5 178

Thanks m8. Thats very close to what I want. Can't I use hotkeys ? '10-commands-limit' seems pretty low – majkinetor – 2012-12-19T14:08:36.897

@majkinetor: hotkeys? If you're generating commands to run, you could write them to a file and then execute vim with vim -c 'source cmdfile' myfile. You may also want to look up -s scriptin and -w scriptout or -W scriptout in the man page, they make it easy to repeat macros across many files. – Thor – 2012-12-19T14:47:02.037