ryanjdillon
ryanjdillon

Reputation: 18968

Block indenting/un-indenting python code in vim

I'm deciding to switch from tabs to spaces in my python code. Previously, if I wanted to indent/unindent a block of code in vim, I would use the >> or << commands.

I'm using the vimrc setup for python by adding it to my ~/.vimrc:

source ~/.vimrc-python

Currently, it appears it is setting new tabs to be 8 spaces wide, and when I block indent/un-indent it moves everything by four spaces.

How might I get everything so that it is consistent?

Upvotes: 4

Views: 3191

Answers (1)

askewchan
askewchan

Reputation: 46530

Try these:

set shiftwidth=4
set tabstop=4
set expandtab

shiftwidth indicates how far to indent with the operations (<< and >>) you are using.

tabstop indicates how far to indent with the tab key.

expandtab converts tabs into spaces.

As [http://stackoverflow.com/users/2241874/bradd-szonye](Bradd Szonye) points out, you can also alternatively do

set shiftwidth=4
set softtabstop=4
set tabstop=8
set expandtab

which means that if there is an actual tab character, it will show as 8 columns, but hitting the tab key gives 4 spaces.

Upvotes: 6

Related Questions