vim & python

S

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?
 
G

Gerrit

sb said:
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.
 
T

Tobias Klausmann

sb said:
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
 
P

poiboy

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.
 
A

Ashot

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.

very nice.
 
G

gabor

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
 
?

=?iso-8859-1?Q?Fran=E7ois?= Pinard

[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.
 
G

Gordon Airport

gabor said:
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.
 
P

poiboy

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
 
S

Simon Burton

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.
 
A

Alan Gauld

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
 
S

Scott F

(e-mail address removed) (Frank Miles) wrote in @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
 
S

sb

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)
 
?

=?iso-8859-1?Q?Fran=E7ois?= Pinard

I have a bunch of questions about using python scripting in vim and
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! :)
 
F

Frank Miles

(e-mail address removed) (Frank Miles) wrote in @nntp6.u.washington.edu:


try
:set showmatch
or
:set sm

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
--
 
D

demian neidetcher

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
 
S

sb

François Pinard said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top