Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set up Vim autoindentation properly for editing Python files?

I've trouble setting up Vim (7.1.xxx) for editing Python files (*.py). Indenting seems to be broken (optimal 4 spaces). I've followed some tutorials I found via Google. Still no effect :/ Please help.

like image 225
M_1 Avatar asked Sep 15 '08 17:09

M_1


People also ask

Is Vim editor good for Python?

Why is Vim a good Python development environment? Vim's philosophy is that developers are more productive when they avoid taking their hands off the keyboard. Code should flow naturally from the developer's thoughts through the keyboard and onto the screen.

Does Vim have auto indentation?

Vim is a modal text editor that allows users to alter text in different modes. These different modes determine how the alphanumeric keys on keyboards function. Vim has an extremely powerful and flexible automatic indent option, indentexpr.


2 Answers

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 expandtab au BufRead,BufNewFile *.h set expandtab 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)

like image 85
Daren Thomas Avatar answered Sep 29 '22 09:09

Daren Thomas


I use:

$ cat ~/.vimrc syntax on set showmatch set ts=4 set sts=4 set sw=4 set autoindent set smartindent set smarttab set expandtab set number 

But but I'm going to try Daren's entries

like image 30
thanos Avatar answered Sep 29 '22 11:09

thanos