8

Possible Duplicate:
How can I automatically add some skeleton code when creating a new file with vim

I googled and searched on SO for a way to create automatic headers when creating a new python file. I was hoping to find something with snipMate but couldn't find anything. I use bash-suport, perl-support that provide this functionality and like it. If it can help I am also a user of python-mode

  1. Is there a way to generate automatic headers with snipMate?
  2. If not where can I find examples ?

I would like something like this:

#!/usr/bin/python
#-*- coding: utf-8 -*-
#===============================================================================
#
#         FILE: test.py
#
#        USAGE: ./test.py  
#
#  DESCRIPTION: 
#
#      OPTIONS: ---
# REQUIREMENTS: ---
#         BUGS: ---
#        NOTES: ---
#       AUTHOR: YOUR NAME (), 
# ORGANIZATION: 
#      VERSION: 1.0
#      CREATED: 09/12/2012 13:38:51
#     REVISION: ---
#===============================================================================


def main():
    """docstring for main"""
pass

Thanks a lot for reading

Community
  • 1
  • 1
statquant
  • 13,672
  • 21
  • 91
  • 162
  • 1
    You could create a new Python snippet for snipmate called something like `py.snippet` and when you open a new file just type `py` to expand it. – Michael Berkowski Dec 09 '12 at 14:01
  • See also http://stackoverflow.com/questions/162617/how-can-i-automatically-add-some-skeleton-code-when-creating-a-new-file-with-vim – Michael Berkowski Dec 09 '12 at 14:03

1 Answers1

13

You don't need Snipmate for that. Save your header to a file, then add the following to your .vimrc:

au BufNewFile *.py 0r /where/you/saved/your/header.template

This inserts your header automatically for every .py file.

If you want a header with variables (e.g. changing dates, revision numbers, filenames, etc.), see this article and this for further help. But there are other plugin(s) to help you out.

Zsolt Botykai
  • 50,406
  • 14
  • 85
  • 110