tags:

views:

98

answers:

2

I want to create a template for all my python scripts using this

autocmd bufnewfile *.py so ~/.vim/templates/python_skeleton.txt

the content of python_sekleton.txt is as simple as this:

#!/usr/bin/python
# -*- coding: utf-8 -*-

print 'Hello World'

but vi give error message when i start to edit a new python script:

line    2:
E488: Trailing characters: # -*- coding: utf-8 -*-
line    4:
E488: Trailing characters: print 'Hello World'

it seems '#' is not escaped,and anyone can work it out?thanks i advance

A: 

The so command sources a file of Ex commands, not directly a Python file. You need to use pyf instead of so to execute a Python file.

Alex Martelli
Thanks also.pyf try to execute the python file.but :r is what I really want.It don't matter.
schemacs
+1  A: 

You want to read the file, not source/execute it.

So use something like the following instead:

autocmd bufnewfile *.py :r ~/.vim/templates/python_skeleton.txt
Jeet
Thanks.This is what i ask for.But vim seems to add a total new line at the begin of the new python file i am try to begin editing.Any idea of what happened this time?
schemacs
Try: autocmd bufnewfile *.py :0r ~/.vim/templates/python_skeleton.txtThe "0" inserts the text at the beginning of the file.
Jeet