By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,991 Members | 1,888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,991 IT Pros & Developers. It's quick & easy.

vim & python

P: n/a
sb
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?
Jul 18 '05 #1
Share this Question
Share on Google+
16 Replies


P: n/a
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/

Jul 18 '05 #2

P: n/a
sb <sp**********@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."
Jul 18 '05 #3

P: n/a
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/g...nq_ipython.png (197K,
1600x1200)
Check out the function prototype on the bottom of GVim's window.
Jul 18 '05 #4

P: n/a
On 1 Mar 2004 17:48:17 -0800, poiboy <bi*******@safe-mail.net> wrote:
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/g...nq_ipython.png (197K,
1600x1200)
Check out the function prototype on the bottom of GVim's window.


very nice.
--
Ashot Petrosian
University of Texas at Austin, Computer Science
Jul 18 '05 #5

P: n/a
Not sure what you mean exactly, but this may do it:

http://members.nccw.net/kdahlhaus/py...n.html#pyhints
Is it possible to enable "calltips" while editing python documents
with vim?

Jul 18 '05 #6

P: n/a
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
Jul 18 '05 #7

P: n/a
[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

Jul 18 '05 #8

P: n/a
gabor wrote:
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


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.

Jul 18 '05 #9

P: n/a
> 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
Jul 18 '05 #10

P: n/a
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.

Jul 18 '05 #11

P: n/a
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
Jul 18 '05 #12

P: n/a
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é
Jul 18 '05 #13

P: n/a
In article <c2*************@ID-112871.news.uni-berlin.de>,
André Kelpe <fs***@linuxmail.org> wrote:
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é


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
--
Jul 18 '05 #14

P: n/a
fp*@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
Jul 18 '05 #15

P: n/a
> > 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/s...?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 |
`-----------------------------------------------------------'
Jul 18 '05 #16

P: n/a
On 4 Mar 2004 18:53:18 -0800, sb <sp**********@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.
Jul 18 '05 #17

This discussion thread is closed

Replies have been disabled for this discussion.