• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 692
  • Last Modified:

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
  • 3
  • 3
1 Solution
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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.

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now