Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Block indenting/un-indenting python code in vim

Tags:

python

vim

pep8

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?

like image 325
ryanjdillon Avatar asked Oct 18 '25 00:10

ryanjdillon


1 Answers

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.

like image 67
askewchan Avatar answered Oct 20 '25 13:10

askewchan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!