Correct indenting in vim

I have a partial HTML file (It's actually Drupal template file with *.tpl.php extension). The root tag is <div>. The file has bad indentation of nested tags (They're on the same level and should be shifted more to the right).

Do you know how to correct the indentation with some vi command? Not manually because the file is quite large.

Things that does not work:

Open in new window

filetype plugin indent on

Open in new window

in .vimrc file

Open in new window

thank you
Who is Participating?
First get the line numbers by going into command mode (Esc) and typing
:se nu

Suppose you want to indent once from line 5 to line 30, you do
This will take you to line 5

Then still being in command mode do

If you want to indent to the end of file, in command mode do

For indenting one line

Indent back

Also you would need to show set tabs so that you can see it well
:se shiftwidth=4
:se tabstop=4
The above two lines should be put in the .vimrc file
If you want to indent from current line to the first line you can do


NOTE: All of the indentation commands would work in the command mode.  Don't put then in the .vimrc file.

Indentation is a very old feature, you should not need any plugins for it.

ONLY put se shiftwidth tabstop commands in the .vimrc file.
xRalfAuthor Commented:
Thank you, but it's quite complex and I've written
no manually
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

xRalfAuthor Commented:
I thought that somebody could wrote a script that is able to utilize XHTML rules and format the file correctly with one command.
Well, looks like you need a script.  I don't think you can correct all the indentation automatically.  I am not sure if there are any plugins that would do it.
xRalfAuthor Commented:
I tried to indent it manually as you advised, with coldfolding it was easier and acceptable. But I will leave the question for sometime open if somebody know about that script.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.