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:
gg=G

Open in new window

filetype plugin indent on

Open in new window

in .vimrc file
<G

Open in new window


thank you
LVL 6
xRalfAsked:
Who is Participating?
 
farzanjCommented:
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
:5
This will take you to line 5

Then still being in command mode do
>30G

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

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
0
 
farzanjCommented:
If you want to indent from current line to the first line you can do
>gg

Or
>1G

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.
0
 
xRalfAuthor Commented:
Thank you, but it's quite complex and I've written
no manually
0
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.
0
 
farzanjCommented:
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.
0
 
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.
0
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.