schemacs
schemacs

Reputation: 2891

vi script problem on autocmd

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

Upvotes: 0

Views: 478

Answers (2)

Jeet
Jeet

Reputation: 39787

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

Upvotes: 1

Alex Martelli
Alex Martelli

Reputation: 881497

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.

Upvotes: 0

Related Questions