9

I was wondering if it is possible to insert something in .bashrc or .vimrc so that whenever I create a new Python file via vim it automatically creates a file with this already inserted before I edit it:

#!/usr/bin/env python

import sys

if __name__ == '__main__':

A vast majority of my Python scripts use those lines, and if there is a way to include those for every newly created Python file I make that would be great.

Thanks! -kstruct

3 Answers 3

12

Or if you want to avoid plugins:

autocmd bufnewfile *.py 0r /path/to/python_default.py
Sign up to request clarification or add additional context in comments.

2 Comments

au BufNewFile *.py 0r ~/.vim/skel/skel.html add 0 to indicate location, in other words, in line 0 add this.
Thanks, that's an important detail.
4

template is a Vim plugin to read the template file automatically when the edit of the file is newly started.  Template file is selected to match the file name to open. Also, you can run any command after the open.

Comments

1

Snipmate is a better version of the TextMate feature. It has a pretty extensible template language that allows you to insert the results of shell commands.

1 Comment

Ultisnips is a better version of snipmate (which is no longer being developed).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.