Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

vim & python

14 views
Skip to first unread message

sb

unread,
Mar 1, 2004, 2:51:24 PM3/1/04
to
Hello

I have a bunch of questions about using python scripting in vim and
about editing python with vim.


I can install vim with python scripting support, but I can not find
docs, examples or tutorials about scripting vim using python anywhere
with google.


Is it possible to enable "calltips" while editing python documents
with vim? (BTW I've read somewhere that pyalamode was created
specifically because someone wanted "calltips" not just in the
interpreter, but in the editor as well. FWIW, VC++ has had calltips
for many years. However, I can not get those calltips to work in
pyalamode either. So I'm anxious to find any editor for python that
has calltips, but I would prefer it to be vim though)


I've heard the biggest python gurus use vim. *Please* post some
screenshots of you in action - some interesting things like
- calltips,
- editor-shell interaction
- reference manual invocation by keyword from within the editor
- object browser,
- etc.
Or are you using vim just like C coders do?

Gerrit

unread,
Mar 1, 2004, 4:27:22 PM3/1/04
to pytho...@python.org
sb wrote:
> Is it possible to enable "calltips" while editing python documents
> with vim?

I don't think so.

> I've heard the biggest python gurus use vim. *Please* post some
> screenshots of you in action - some interesting things like
> - calltips,
> - editor-shell interaction
> - reference manual invocation by keyword from within the editor
> - object browser,
> - etc.
> Or are you using vim just like C coders do?

I'm using it 'like C coders', if that means that I do happily use syntax
highlighting, auto-indentation and line-numbering, but not anything
else.

Note that I'm not one of the biggest python gurus ;-)

Gerrit.

--
Weather in Twenthe, Netherlands 01/03 20:25 UTC:
3.0°C wind 3.6 m/s W (57 m above NAP)
--
Asperger's Syndrome - a personal approach:
http://people.nl.linux.org/~gerrit/english/

Tobias Klausmann

unread,
Mar 1, 2004, 5:09:32 PM3/1/04
to
sb <spam_b...@yahoo.com> wrote:
> I've heard the biggest python gurus use vim. *Please* post some
> screenshots of you in action - some interesting things like
> - calltips,
> - editor-shell interaction
> - reference manual invocation by keyword from within the editor
> - object browser,
> - etc.
> Or are you using vim just like C coders do?

While definitely not being a guru I use vims Syntax highlighting
plus these settings for all files ending in .py:

highlight Comment ctermfg=white

set smartindent
cinwords=if,elif,else,for,while,try,except,finally,def,class
set tabstop=4
set shiftwidth=4
set smarttab
set expandtab
set softtabstop=4
set autoindent

Depending on your style of coding you might want to tune them,
but they're pointers. They most probably have room for
improvement, too.

As for calltips, shell interaction and all the othe nifty stuff:
I don't use it. And while they sometimes sound cool I always
ended up being more annoyed than helped by them.

Greets,
Tobias

--
Thank you for calling $PROVIDER helpdesk. If your cupholder is
broken, please press 1. If you want an actual knowledgable support
person, please enter the IP representation of a /28 netmask."

poiboy

unread,
Mar 1, 2004, 8:48:17 PM3/1/04
to
Look at taglist.vim (links below), a popular souce-browsing Vim
script. It's the only major script I'm using right now. I don't know
of any definitive Python calltips available for Vim (I assume they
would be difficult with flexible parameters and return values), but
taglist.vim provides function prototypes in the form of parameter
lists (search for 'prototype' in the taglist docs).

I've tried a few nifty Python-specific scripts (search www.vim.org)
but always wound up forgetting the special commands and resorting to
Vim staples. For example, the following two lines in my .vimrc were
good enough to condense all the functions and classes in a file:

set foldmethod=indent
set foldnestmax=2

My .vimrc also includes this "execute code and output results in new
buffer" script (which should all be on one line):

map <F4> :w<CR>:let @a = system('`which python` ' .
bufname('%'))<CR>:silent botright new output<CR>:silent normal "aP<CR>

Normally I use GVim next to a terminal window tabbed with IPython
(ipython.scipy.org/) and a browser tabbed with whatever documentation
I may need - Python docs, RFCs, and project docs
(epydoc.sourceforge.net/). IPython helps access the nitty-gritty
aspects of Python, Epydoc allows me to browse documentation and
package structures elegantly. And though I am by no means a Python
guru, I've posted a screenshot of my "modular IDE" in action (link
below).

I went through a do-it-all-in-Vim stage and left feeling as though I
had just spent too much time playing with my tool. Keeping a browser
and terminal open all the time anyway, I eventually dismissed the
all-in-one paradigm as some quixotic jab at Emacs.

Happy vimmings,
poiboy

taglist.vim
http://www.vim.org/scripts/script.php?script_id=273

exuberant ctags
http://ctags.sourceforge.net/

screenshot
http://aonalu.makahavalley.org/img/gvim_konq_ipython.png (197K,
1600x1200)
Check out the function prototype on the bottom of GVim's window.

Ashot

unread,
Mar 2, 2004, 4:47:09 AM3/2/04
to

very nice.


--
Ashot Petrosian
University of Texas at Austin, Computer Science

Kevin Dahlhausen

unread,
Mar 2, 2004, 10:19:27 AM3/2/04
to
Not sure what you mean exactly, but this may do it:

http://members.nccw.net/kdahlhaus/python/python.html#pyhints

gabor

unread,
Mar 2, 2004, 10:02:19 AM3/2/04
to poiboy, pytho...@python.org
On Tue, 2004-03-02 at 02:48, poiboy wrote:
> Normally I use GVim next to ....

i always wanted to ask this...
why people use GVIm and not the normal-vim-in-a-terminal?

what is the advantage of gvim?

thanks,
gabor


François Pinard

unread,
Mar 2, 2004, 10:20:17 AM3/2/04
to gabor, pytho...@python.org, poiboy
[gabor]

> i always wanted to ask this... why people use GVIm and not the
> normal-vim-in-a-terminal? what is the advantage of gvim?

Mainly the ability to use the mouse for some quick operations, like
positioning the cursor between two characters, moving big distances by
dragging scroll bars, changing window dimensions by dragging the bars
between windows, wandering in help through clicking on index items,
clicking within the fold margin for opening and closing folds, etc.

I'm usually not fond on the mouse, but strangely (to me at least),
`gvim' is effectively taming me into using it. One thing which I often
do is repeating mouse fast positioning of the cursor with `.' typed with
the left hand. It is also surprising how many `vim' operations you can
quickly do with the left hand alone! :-)

One thing which helped me a lot is that, right from the beginning, I
took the time of carefully customising `gvim' so it uses readable fonts,
consistent colours, and such things. As for Python editing, of course,
`vim' customisation is equally available within and outside X.

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

Gordon Airport

unread,
Mar 2, 2004, 12:10:01 PM3/2/04
to

So when you need to use a command that you don't use frequently you
don't have to dig through docs somewhere, you can just find it in the
menus. Or, if you work in windows it's more natural.

poiboy

unread,
Mar 2, 2004, 3:09:39 PM3/2/04
to
> what is the advantage of gvim?

I switched to GVim after moving from desktop/mouse to
laptop/trackpoint because trackpointers (a must-have, little knobby
joystick in the middle of the keyboard) eliminate the expense of small
pointer movements (if any IBM reps are reading, I am your ThinkPad
cheerleader). On the desktop, I felt most comfortable leaving the
mouse alone and using 'screen'
(http://www.gnu.org/software/screen/screen.html) to organize multiple
Vim windows.

In addition to the benefits already mentioned, GVim maintained better
speed than Vim after I added:

autocmd BufEnter * :syntax sync fromstart

to alleviate (brutally) highlighting consistency problems with larger
files (500+ lines or so).

Aloha,
the poiboy

Simon Burton

unread,
Mar 2, 2004, 6:59:27 PM3/2/04
to
On Mon, 01 Mar 2004 11:51:24 -0800, sb wrote:

> Hello
>
> I have a bunch of questions about using python scripting in vim and about
> editing python with vim.
>
>

I'm very happy with word completion.

From ":help ins-complet":

For example, the following will map <Tab> to either actually insert a <Tab> if
the current line is currently only whitespace, or start/continue a CTRL-N
completion operation: >

function! CleverTab()
if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
return "\<Tab>"
else
return "\<C-N>"
endfunction
inoremap <Tab> <C-R>=CleverTab()<CR>

I found out about this wrt "pydiction" which parses python files
and outputs a diction file with words for vim to complete on. However,
I don't use it, as it pollutes the completion namespace too much.

Simon.

Alan Gauld

unread,
Mar 2, 2004, 7:05:38 PM3/2/04
to
On Tue, 02 Mar 2004 16:02:19 +0100, gabor <ga...@z10n.net> wrote:
> i always wanted to ask this...
> why people use GVIm and not the normal-vim-in-a-terminal?

Mouse support
marking regions,
resizing windows,
Pinnable menus
The toolbar
Better colour choices.
Better integration with Windoze(clipboard etc)
Bigger windows (but an xterm fixes that...)

Those are my main reasons.

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld

André Kelpe

unread,
Mar 3, 2004, 5:34:11 AM3/3/04
to
sb wrote:

> Hello

Hi!

> - reference manual invocation by keyword from within the editor

Please try my pydoc.vim, it is available at:

http://www.vim.org/scripts/script.php?script_id=910

> - object browser,

Use taglist.vim, it is great!

André

Frank Miles

unread,
Mar 3, 2004, 10:59:20 AM3/3/04
to
In article <c24cb3$1oj5g2$1...@ID-112871.news.uni-berlin.de>,

Thanks Andre, that looks great!

Now if I could only get vim to highlight paren/bracket/curly-bracket
completion as it does when editing shell scripts!

-frank
--

Scott F

unread,
Mar 3, 2004, 11:34:28 AM3/3/04
to
f...@u.washington.edu (Frank Miles) wrote in news:c24vco$9ro$1
@nntp6.u.washington.edu:

>
> Now if I could only get vim to highlight paren/bracket/curly-bracket
> completion as it does when editing shell scripts!

try
:set showmatch
or
:set sm

Scott

sb

unread,
Mar 4, 2004, 2:32:05 AM3/4/04
to
spam_b...@yahoo.com (sb) wrote in message news:<221dd125.04030...@posting.google.com>...

> I have a bunch of questions about using python scripting in vim and
> about editing python with vim.

Thanks for all of the answers to the second question, but what about
vim scripting with python? I can not find *anything* about it (no
docs, books or tutorials)

Frank Miles

unread,
Mar 4, 2004, 10:40:00 AM3/4/04
to
In article <Xns94A16B9186C0...@216.168.3.44>,

Thanks, but that only works for characters as you edit them. The highlighting
method shows mismatches immediately. I haven't delved into vim to see how
it's done with shell scripts.

-frank
--

François Pinard

unread,
Mar 4, 2004, 10:33:57 AM3/4/04
to sb, pytho...@python.org
> > I have a bunch of questions about using python scripting in vim and
> > about editing python with vim.

> Thanks for all of the answers to the second question, but what about
> vim scripting with python? I can not find *anything* about it (no
> docs, books or tutorials)

Just do:

:h python

in Vim, to get a compact, yet very usable description of Vim scripting
capabilities. On my machine, this command displays the contents of:

/usr/share/vim/vim62/doc/if_pyth.txt

You might have to recompile Vim with Python-enabled, if not already. If
you visit the Vim site, you might search the scripts for those based on
Python extensibility, too. I wrote one such script as an exercise (but
also to cover one of my needs), you might find it from my home page (see
my signature), picking "FP Etc.", then looking around for "Allout-Vim".

I use Python scripting of Vim very regularly, and it works wonderfully
for me. I hope it will for you as well! :-)

demian neidetcher

unread,
Mar 4, 2004, 9:13:18 PM3/4/04
to
> Thanks for all of the answers to the second question, but what about
> vim scripting with python? I can not find *anything* about it (no
> docs, books or tutorials)

i'm not using the built-in integration that can be built into vim. my
vim scripting with python is really just re-directing lines in a file
from vim thru a python script that reads from std in (your code from
vim) and writes to std out (the results replace your old lines).

here are some scripts i have, might give you an idea of what i'm
doing.
http://www.ophinity.com/papers/wrangling/index.html

sb

unread,
Mar 4, 2004, 9:53:18 PM3/4/04
to
François Pinard <pin...@iro.umontreal.ca> wrote in message news:<mailman.15.10784148...@python.org>...

> > > I have a bunch of questions about using python scripting in vim and
> > > about editing python with vim.
>
> > Thanks for all of the answers to the second question, but what about
> > vim scripting with python? I can not find *anything* about it (no
> > docs, books or tutorials)
>
> Just do:
>
> :h python
>

Thanks, but that is more like a very abbreviated tutorial. Where can I
can the real documentation? It seems like the python built into vim is
different. For example, doing

:py import sys
:py dir(sys)

produces no output. Odd. Same with

:py import vim
:py dir(vim)


Anyway, I want the real documentation for the "vim" module accessible
from vim. What classes, functions, values are defined there, etc

François Pinard

unread,
Mar 4, 2004, 11:44:52 PM3/4/04
to sb, pytho...@python.org
[sb]

> > > [...] but what about vim scripting with python? I can not find


> > > *anything* about it (no docs, books or tutorials)

> > Just do:
> > :h python

> Thanks, but that is more like a very abbreviated tutorial.

I did not read it as a tutorial, but as a concise and useful reference.

> Where can I can the real documentation? It seems like the python

> built into vim is different. [...] I want the real documentation for


> the "vim" module accessible from vim. What classes, functions, values
> are defined there, etc

The real documentation is the usual Python documentation, all that we
use outside Vim, plus the result of `:h python' for classes, functions
and values specific to Vim. There is not much of them, but there is no
need for much either; what is provided is surely sufficient for a great
lot of applications.

> For example, doing

> :py import sys
> :py dir(sys)

> produces no output. Odd. Same with

> :py import vim
> :py dir(vim)

The same would not give you output in Python either (unless you run
Python in an interactive read-eval-print loop, like when you call Python
without arguments from an interactive shell). However, you may use:

:py print dir(sys)
...
:py print dir(vim)

You have to ask for printing, if you want printing.

Antony Scriven

unread,
Mar 5, 2004, 5:40:12 AM3/5/04
to
spam_bait101 wrote:

> François Pinard <pin...@iro.umontreal.ca> wrote [...]


>
> > > Thanks for all of the answers to the second question, but what about
> > > vim scripting with python? I can not find *anything* about it (no
> > > docs, books or tutorials)
> >
> > Just do:
> >
> > :h python
> >
>
> Thanks, but that is more like a very abbreviated tutorial. Where can I

> can the real documentation? [...]


> I want the real documentation for the "vim" module accessible
> from vim. What classes, functions, values are defined there, etc

:let @/='The vim module'|se hls
:h python

Is that not it?

Antony

Mikolaj Machowski

unread,
Mar 5, 2004, 6:09:06 AM3/5/04
to
sb scripsit:

> François Pinard <pin...@iro.umontreal.ca> wrote in message news:<mailman.15.10784148...@python.org>...
>> > > I have a bunch of questions about using python scripting in vim and
>> > > about editing python with vim.
>>
>> > Thanks for all of the answers to the second question, but what about
>> > vim scripting with python? I can not find *anything* about it (no
>> > docs, books or tutorials)
>> Just do:
>> :h python
> Thanks, but that is more like a very abbreviated tutorial. Where can I
> can the real documentation? It seems like the python built into vim is
> different. For example, doing

Note: python isn't built _into_ Vim. This is only interface to "real"
python.

m.
--
LaTeX + Vim = http://vim-latex.sourceforge.net/
Learn Touch Typing with Vim? Oui. Ja. Yes. Tak:
http://vim.sourceforge.net/script.php?script_id=461
vim.pl - http://skawina.eu.org/mikolaj

Brian Sturk

unread,
Mar 16, 2004, 9:35:44 PM3/16/04
to
> > I have a bunch of questions about using python scripting in vim and
> > about editing python with vim.
>
> Thanks for all of the answers to the second question, but what about
> vim scripting with python? I can not find *anything* about it (no
> docs, books or tutorials)

I don't have a tutorial, but I've written a quite large python script for
vim called vimsh. It might be helpful for you as a reference:

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

hth,
~brian

--
.--------------------------------------------------,--------.
| Brian Sturk - http://users.adelphia.net/~bsturk \ C/C++ |
|-------------------------. bsturk<AT>adelphia.net | Python |
| http://www.telengard.com `------------------------`-------|
| Telengard Technologies Inc. - NT/*nix UI & device drivers |
`-----------------------------------------------------------'


C. Laurence Gonsalves

unread,
Mar 26, 2004, 11:45:45 AM3/26/04
to
On 4 Mar 2004 18:53:18 -0800, sb <spam_b...@yahoo.com> wrote:
> Thanks, but that is more like a very abbreviated tutorial. Where can I
> can the real documentation? It seems like the python built into vim is
> different. For example, doing
>
> :py import sys
> :py dir(sys)
>
> produces no output. Odd.

The statement 'dir(sys)' doesn't produce any output in Python. What's
confusing you is that the interactive mode of the python interpreter
prints the values of expression statements, if the value is not None.
That's a feature of the interactive mode though, not of Python, the
language.

You can verify this for yourself by creating a little script:

import sys
dir(sys)

Copy the above to a file, test.py. The lines should not be indented, of
course. Then execute 'python test.py' from the shell. Note the lack of
output.

In vim, just as in Python scripts, if you want output you need to
explicitly ask for it. So try the following in vim:

:py import sys
:py print dir(sys)

BTW, the "python built into vim" is really just the normal python
interpreted, embedded in vim. Everything you know about the Python
language still holds. The main differences are that it doesn't have the
same sort of "interactive mode" that the python interpreter has, and you
have access to he vim module. Documentation for the latter can be found
by executing ':help python-vim'. Yes, the documentation is brief, but it
is fairly complete, as far as I can tell.

0 new messages