Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm wondering if it's possible with vim to create a macro which will run only on new blank files given a certain filetype.

I'd personally like that when I create xy.tex it will automatically populate the document with my headers, etc. I realise I can run a command on opening a file by execute "echo blah" or whatever, but I'm not really sure how I'd go about executing ONLY on a new (Blank) file. Any ideas?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Use the BufNewFile autocommand event. See :h autocmd.txt for more details.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.