views:

5791

answers:

8

I've troubles setting VIM (7.1.xxx) for editing python files. Identing seems broken (optimal 4 spaces). I've followed some tutorials I found via google. Still no effect :/ Please help.

+8  A: 

I use this on my macbook:

" configure expanding of tabs for various file types
au BufRead,BufNewFile *.py set expandtab
au BufRead,BufNewFile *.c set noexpandtab
au BufRead,BufNewFile *.h set noexpandtab
au BufRead,BufNewFile Makefile* set noexpandtab

" --------------------------------------------------------------------------------
" configure editor with tabs and nice stuff...
" --------------------------------------------------------------------------------
set expandtab           " enter spaces when tab is pressed
set textwidth=120       " break lines when line length increases
set tabstop=4           " use 4 spaces to represent tab
set softtabstop=4
set shiftwidth=4        " number of spaces to use for auto indent
set autoindent          " copy indent from current line when starting a new line

" make backspaces more powerfull
set backspace=indent,eol,start

set ruler                           " show line and column number
syntax on      " syntax highlighting
set showcmd    " show (partial) command in status line

(edited to only show stuff related to indent / tabs)

Daren Thomas
A: 

Usually the default configuration is fine so please detail your problem and if possible include your configuration and where you got it from.

Corporal Touchy
A: 

vim test.py [insert]

!/usr/bin/python

for x in range(1,10):[here enter should get cursor to the next line, and ident 4 spaces] [doesn't work, TAB should be 4 spaces, it's not]

:(

On my laptop it's the default behavior for Vim in Debian Etch and Fedora 9 Sulphur.

Murzyn1
+19  A: 

http://www.sontek.net/post/Python-with-a-modular-IDE-%28Vim%29.aspx

mmattax
used tarred config file from the blog, worked like a charm, thanks.
Murzyn1
This is terrific are there setups like this for other programming languages available somewhere? Of course it would be easy to adapt but who isn't lazy? :)
Corporal Touchy
The new url is: http://www.sontek.net/post/Python-with-a-modular-IDE-%28Vim%29.aspx
da01
A: 

Ensure you are editing the correct configuration file for VIM. Especially if you are using windows, where the file could be named _vimrc instead of .vimrc as on other platforms.

In vim type

:help vimrc

and check your path to the _vimrc/.vimrc file with

:echo $HOME

:echo $VIM

Make sure you are only using one file. If you want to split your configuration into smaller chunks you can source other files from inside your _vimrc file.

:help source

Jamie
A: 

for more advanced python editing consider installing the simplefold vim plugin. it allows you do advanced code folding using regular expressions. i use it to fold my class and method definitions for faster editing.

Gabor
A: 

I found this page very helpful:

Vim Python development

Ben Hoffstein
+1  A: 

If y'all want to help build a vim IDE for python, FORK!

http://github.com/skyl/vim-config-python-ide

I symlink from the repo to my vimconfig area and then I can change my repo with git branch.

You can look at an official python take which my werk is based on.

http://svn.python.org/projects/python/trunk/Misc/Vim/vimrc

at the end I add

setlocal softtabstop=4

So I can hit tab and it will be 4 spaces (if there are no leading characters that would cause supertab to kick in).

skyl