how can I easily indent html files with linux or vi or 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.
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.
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 .
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
Use an HTML tidy plugin. Here is some help for vim
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With