vikas srivastava vikas srivastava - 1 year ago 114
Python Question

Auto indentation in VIM, version 7.4.52, Operating Sysytem :Ubuntu 14.04

I am new to this programming world, currently I am reading from "Introduction to Computation and programming using Python " by John V Guttag , MIT press.

How can I set the auto indentation on in VIM. What's happening now is that when I press enter after : it starts from new line.

Is it possible ?

Ben Ben
Answer Source

Vim comes with several language indentation presets. To enable them, you need to add the following to Vim's user configuration file (~/.vimrc):

filetype indent plugin on

An easy way to do this from the terminal:

echo "filetype indent plugin on" >> ~/.vimrc

This appends the command to your .vimrc, creating it if necessary.

then open up a .py file and define a function.

Note: there are several other settings that can be very helpful to Python programmers and the link from @birryree looks pretty complete.

I also use

set expandtab " Use spaces instead of tabs set shiftwidth=4 " Number of auto-indent spaces set softtabstop=4 " Number of spaces per Tab

in my .vimrc to follow PEP8.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download