Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim / vi / linux: properly indent html file

how can I easily indent html files with linux or vi or vim.

like image 652
flybywire Avatar asked Sep 21 '09 09:09

flybywire


People also ask

How do I indent an entire file in Vim?

Start in the top of a file (to get there, press gg anywhere in the file.). Then press =G , and Vim will fix the indentation in the whole file. If you don't start in the beginning of the file, it will fix indentation from current line to the bottom of file.

Does Vim have auto indent?

Vim offers four increasingly complex and powerful methods to automatically indent text. In its simplest form, Vim behaves almost identically to vi 's autoindent option, and indeed it uses the same name to describe the behavior.

How do you indent a block in vi?

Use the > command. To indent five lines, 5 > > . To mark a block of lines and indent it, V j j > to indent three lines (Vim only). To indent a curly-braces block, put your cursor on one of the curly braces and use > % or from anywhere inside block use > i B .


3 Answers

If your vim knows it's an html file (:se filetype=html), you can use the default indentation method (gg=G). I would have a look at :help =, it's quite powerful

like image 199
soulmerge Avatar answered Oct 22 '22 23:10

soulmerge


Use an HTML tidy plugin. Here is some help for vim

like image 36
Charles Ritchie Avatar answered Oct 22 '22 22:10

Charles Ritchie


You can use the html tidy program to have your html file(s) indented. It could also potentially correct things and change more than just indentation, so it might do more than you ask for, but unless that is a problem you will end up with better html files as a result of running tidy.

like image 2
hlovdal Avatar answered Oct 22 '22 21:10

hlovdal