vim configuration for python

L

Leonard J. Reder

Hello,

I am looking at configuring vim for Python. Most importantly I
need 4 spaces when the tab is hit. I am searching and getting
a bit confused. Does anyone know where I can find a set of
ready made .vimrc and ~/.vim/syntax/python.vim. If could find
c.vim and cpp.vim these would be useful also.

Thanks for any pointer.
Len
--
____________________________________________________
Leonard J. Reder
Jet Propulsion Laboratory
Interferometry Systems and Technology Section 383
Email: (e-mail address removed)
Phone (Voice): 818-354-3639
Phone (FAX): 818-354-4357
Mail Address:
Mail Stop: 171-113
4800 Oak Grove Dr.
Pasadena, CA. 91109
---------------------------------------------------
 
H

haihui guo

I think you can do

set tabstop=4

also, it's better to

set expandtab

so, the tab will be expanded as space.

HG
 
S

Simon Percivall

I don't know if the binary editions include the Misc directory, but if
you download the Python source you'll find a directory called Misc. In
it, there's a vimrc file.
 
S

Stephen Thorne

Hello,

I am looking at configuring vim for Python. Most importantly I
need 4 spaces when the tab is hit. I am searching and getting
a bit confused. Does anyone know where I can find a set of
ready made .vimrc and ~/.vim/syntax/python.vim. If could find
c.vim and cpp.vim these would be useful also.

The default python.vim in the /usr/share/vim/vim63/ftplugin/ directory
automatically set the shiftwidth to 4 wide (i.e. a <tab> keypress
makes 4 spaces) and automatically uses spaces instead of tab
characters. A tab character in your file will be rendered as 8 wide.
 
G

Gary Johnson

In comp.editors Leonard J. Reder said:
Hello,

I am looking at configuring vim for Python. Most importantly I
need 4 spaces when the tab is hit. I am searching and getting
a bit confused. Does anyone know where I can find a set of
ready made .vimrc and ~/.vim/syntax/python.vim. If could find
c.vim and cpp.vim these would be useful also.

The vim distribution already contains python.vim files for syntax,
indenting and general configuration. It also contains a similar set
of c.vim and cpp.vim files. These should all be in the appropriate
subdirectories under $VIMRUNTIME. You might take a look at

:help ftplugins
:help filetype-indent-on
:help filetype-overview
:help usr_43.txt
:help usr_06.txt

If the files supplied with vim for Python don't do what you want,
you might also search the scripts and tips at vim.sf.net for
"python".

HTH,
Gary
 
G

Gary Johnson

In comp.editors DJK said:
Does anybody know of any scripts to check python syntax when you type
:make?

The problem I had doing this with Python was that the Python
interpreter spits out errors in the opposite order from that in
which I wanted to traverse them in vim's quickfix error list. I
wrote the following compiler file and helper script to work around
this. I don't use Python very often and haven't used in it a while,
so this still isn't very polished, but you might find it useful
anyway. Note also that I did this on a Unix system.

------------------------- compiler/python.vim --------------------------
" Vim compiler file
" Compiler: Python
" Maintainer: Gary Johnson <[email protected]>
" Last Change: 2002-06-26 00:27:56

if exists("current_compiler")
finish
endif
let current_compiler = "python"

setlocal makeprg=python\ %
setlocal shellpipe=2>&1\ \|\ ~/.vim/tools/efm_filter.py\ \|\ tee
" Note: efm_filter.py could be rewritten to send its input to stdout
" and to write its output to the file given on the command line. This
" way the user could see the familiar output from Python while the
" quickfix error file received the format the vim can understand. E.g.,
"
" setlocal shellpipe=2>&1\ \|\ ~/.vim/tools/efm_filter.py
"
" or
"
" setlocal shellpipe=2>&1\ \|\ tee\ /dev/tty\ \|\ ~/.vim/tools/efm_filter.py

setlocal errorformat=\ \ File\ \"%f\"\\,\ line\ %l\\,\ in\ %*[^\\,]\\,\ %m
------------------------------------------------------------------------

------------------------- tools/efm_filter.py --------------------------
#!/usr/bin/env python

import sys
import string

errors = sys.stdin.readlines()

message = errors.pop()[:-1]
errors.reverse()

for error in errors:
if string.find(error, ' File') == 0:
print error[:-1] + ", " + message
message = "Traceback"
------------------------------------------------------------------------

To use these, put them in the indicated directories under ~/.vim and
execute ":compiler python". Also see ":help compiler".

HTH,
Gary
 

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,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top