3

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!

2 Answers 2

2

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

3

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

You must log in to answer this question.

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