Program Python in VIM

Eric Wilhelm ewilhelm at somethinglike.sbcglobalDOTnet
Thu Jan 22 17:51:46 EST 2004


On Thu, 22 Jan 2004 13:08:33 -0600, Paul Moore wrote:

> Peter Wu <peterwu at hotmail.com> writes:
> 
>> I'm giving vim a try to program Python. The following are the steps I
>> follow to code/test a python program.
>>
>> vi test.py
>> [key in some python code]
>> :wq
>> :!python test.py
>>
>>
>> Is there any other way? I don't want to type 'python test.py' every
>> time I've made any modifications. In Emacs, I can simply fire C-c C-c
>> to fire the python interpreter. Thanks!
> 
> There's always
> 
> :map ^C^C :w^M:!python %^M
> 
> which makes C-c C-c write the file and then run it in Python.

This is good, but what about starting your file with #!/usr/bin/python,
setting it as executable with :!chmod 755 %, and then leaving python out
of the "run this file" line?  Advantage here is that you can then be a
Perl programmer as well, or even toss-off some of those really simple
deals in Bash script.

Another suggestion:  maybe leave the ^M off of the end so that you can ^c^c
<enter> or add some arguments if needed.

Of course, if you want emacs-style bindings, you could just use emacs:)
I'd be more inclined to connect this one to something closer to the
escape key and lose the bucky bits.

--Eric



More information about the Python-list mailing list