Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 recently started learning vim and, I'm curious, what's the best way to setup a sort of bare-bones template for specific types of files?

For example: say I wanted to automatically load some C #includes and the main() call with a keystroke (or whenever I create a new .c file) What's the most efficient way to do this?

I was thinking I could write a vimscript function and then map that to a key, or turn it into a macro, but I don't think the macro would be permanent, correct?

Any ideas? All help is appreciated. Thanks!

share|improve this question
up vote 1 down vote accepted

I use something like this:

au BufNewFile * silent! 0r ~/.vim/skeleton/template.%:e

This creates an autocommand that loads a template file for each new file it opens. %:e expands to the file extension, so opening a new file test.h would load boiler plate ~/.vim/skeleton/template.h

You can then add whatever you want inside template.h

share|improve this answer

I use SnipMate for that but there are many other ways.

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.