markle976
markle976

Reputation: 967

How do i fix the indents in my html/php files in vim?

I am (slowly) making the switch to vim. I have added some settings to my .vimrc file (:syntax enable, :fileype plugin on, autoindent, etc.). Everything works great except when I try to indent lines using >. It double indents:

<div>
----<p>this line was autoindented </p>
</div>

<div>
--------<p>this line was indented using the > key </p>
</div>

I am a bit of a vim noob. Any help is greatly appreciated.

Upvotes: 1

Views: 467

Answers (2)

cincodenada
cincodenada

Reputation: 3097

You need to set tabstop and shiftwidth to the desired size - add this to your .vimrc:

set tabstop=4
set shiftwidth=4
set expandtab

You can read up about it on the Vim wiki.

If you don't have expandtab set, add that too - it converts tabs to spaces. If you have a file that has mixed tabs and spaces, :retab will go through and convert everything to your current settings as well.

Your example seems odd, because autoindent should, as far as I know, take its setting from shiftwidth - so they should be the same. You are indenting the single line with >>, correct?

Upvotes: 1

Isaac
Isaac

Reputation: 957

Make sure both of the following are set in your .vimrc file

set tabstop=4
set shiftwidth=4

Upvotes: 2

Related Questions