473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Program Python in VIM

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!

--
,,,
(o o) Peter Wu
---ooO-(_)-Ooo--- Powered by GNU/Linux 2.4.22
Jul 18 '05 #1
9 3377
[Peter Wu]
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!


I do not know if there is a better way, but what I do for one is to
create a small Makefile like:
try:
python test.py
(there is really a TAB above), and then, from `vim', do `:make'.

--
François Pinard http://www.iro.umontreal.ca/~pinard

Jul 18 '05 #2
from the VIM FAQ...

30.1. Can I run a shell inside a Vim window?

Currently Vim doesn't have support for running shell and other external
commands inside a Vim window.

For more information, read

:help shell-window

Alternatively, you can try using the Unix "screen" utility or the 'splitvt'
program.

You can also use the vimsh plugin by Brian Sturk to run a shell in a Vim
window. To use this you need to have Vim built with python support. For
more information visit the following URL:

http://vim.sourceforge.net/scripts/s...?script_id=165

On Thu, 22 Jan 2004 11:17:56 -0500, Peter Wu wrote
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!

--
,,,
(o o) Peter Wu
---ooO-(_)-Ooo--- Powered by GNU/Linux 2.4.22
--
http://mail.python.org/mailman/listinfo/python-list


Jul 18 '05 #3
Peter Wu <pe*****@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.

Paul.
--
This signature intentionally left blank
Jul 18 '05 #4
François Pinard wrote:
I do not know if there is a better way, but what I do for one is to
create a small Makefile like:

try:
python test.py


I use a similar Makefile, and then I bind F4 to "make" in my .vimrc:

map ^[[14~ :make^M

To make that work, you have to make liberal use of control-V. Type:

map <ctrl-V><F4> :make<ctrl-V><enter>

into your .vimrc, and F4 should be bound to the make command.
One-keystoke running! (Does that violate an amazon patent?...)

--
Brian
Jul 18 '05 #5
On Thu, 22 Jan 2004 19:08:33 +0000, Paul Moore
<pf******@yahoo.co.uk> wrote:
Peter Wu <pe*****@hotmail.com> writes:
vi test.py
[key in some python code]
:wq
You should only need :w here. The q will close the window which
presumably you don't want?

:!python test.py
Is there any other way? I don't want to type 'python test.py' every time
:!!

repeats the last command.

However if you are using vim in a *nix terminal rather than the
GUI version you could use CTRL-Z to suspend vim then run python
foo.py from the shell prompt. Resume python, edit and CTRL Z
again. !! at the prompt will repeat the last run command.

...In Emacs, I can simply fire C-c C-c to fire


:!! is probably the nearest direct equivalent.

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
Jul 18 '05 #6
On Thu, 22 Jan 2004 13:08:33 -0600, Paul Moore wrote:
Peter Wu <pe*****@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
Jul 18 '05 #7
> > > :!python test.py


Is there any other way? I don't want to type 'python test.py' every time


:!!

repeats the last command.


% is the symbol for "current file name," so I use:

:w
:!python %

then thereafter in the current vi session:
:!!

It would be nice to be able to combine the write and shell command in
one single command...

Mike
Jul 18 '05 #8
mi**@mhuffman.com (Mike Huffman) wrote in
news:3a**************************@posting.google.c om:

:w
:!python %

then thereafter in the current vi session:
:!!

It would be nice to be able to combine the write and shell command
in one single command...


This should do it.

map <somekey> :w<CR>:!python %<CR>

Scott
Jul 18 '05 #9
Scott F <sdfATexpertuneDOTcom> wrote in message news:<Xn*****************************@216.168.3.44 >...
This should do it.

map <somekey> :w<CR>:!python %<CR>


It does indeed, Thanks!

Unfortuantely I do not use vi consistently enough to ever get beyond
the basics. Had some false starts finding a good key to map that
worked on all my vi installations (Linux, Cygwin, Windows console);
settled on Ctrl-K: unused and easy to type.

Actually, at the moment I am using the maping for Perl, but don't tell
anyone :-)

Mike
Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tim Fuehner | last post by:
Dear Newsgroup, I have a problem that is somewhat related to Alexandre Gillet's ones: "build a static python executable". I would like to make a C program scriptable. Therefor, I have included...
0
by: Jeffrey Barish | last post by:
I have been developing a Python program with two intercommunicating (using sockets) parts, one of which runs on a desktop and the other on a PDA. For ease of development, I developed them both on...
0
by: Praveen, Tayal (IE10) | last post by:
Hi Guys, I am having problems in the following C API program where myOtim_system is callable from python function. The module is listed below - static PyObject * myOptim_system(PyObject...
17
by: los | last post by:
Hi, I'm trying to create a program similar to that of Google's desktop that will crawl through the hard drive and index files. I have written the program and as of now I just put the thread to...
29
by: 63q2o4i02 | last post by:
Hi, I'm interested in using python to start writing a CAD program for electrical design. I just got done reading Steven Rubin's book, I've used "real" EDA tools, and I have an MSEE, so I know what...
0
by: metaperl | last post by:
A Comparison of Python Class Objects and Init Files for Program Configuration ============================================================================= Terrence Brannon bauhaus@metaperl.com...
1
by: Jim Langston | last post by:
Windows. Situation: Using a Python program called OpenRPG. I have a program that displays form data (a character sheet) in C++. I am able in the C++ program to build a string and copy it into the...
8
by: karthikbalaguru | last post by:
Hi, One of my python program needs tkinter to be installed to run successfully. I am using Redhat 9.0 and hence tried installing by copying the tkinter-2.2.2-36.i386.rpm alone from the CD 3 to...
1
by: =?ISO-8859-1?Q?Andr=E9?= | last post by:
Hi everyone, I'd be interested in hearing suggestions as to the "best" way to drive a Python program step by step from another application. Details: --------- I have implemented a "Robot"...
0
by: bruce | last post by:
hi mike.... you might look at/into selenium, or firewatir.... check the spellings! -peace -----Original Message-----
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.