Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ofcourse.

share|improve this question
up vote 4 down vote accepted

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.

share|improve this answer
    
Thanks m8. Thats very close to what I want. Can't I use hotkeys ? '10-commands-limit' seems pretty low – majkinetor Dec 19 '12 at 14:08
    
@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 Dec 19 '12 at 14:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .