简体   繁体   中英

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.

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

set tabstop=4
set shiftwidth=4

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM