How do I tidy up an HTML file's indentation in VI?

后端 未结 11 1877
庸人自扰
庸人自扰 2020-11-29 15:02

How do I fix the indentation of his huge html files which was all messed up?

I tried the usual \"gg=G command, which is what I use to fix the indentation of code fil

11条回答
  •  清酒与你
    2020-11-29 15:57

    As tylerl explains above, set the following:

    :filetype indent on
    :set filetype=html
    :set smartindent
    

    However, note that in vim 7.4 the HTML tags html, head, body, and some others are not indented by default. This makes sense, as nearly all content in an HTML file falls under those tags. If you really want to, you can get those tags to be indented like so:

    :let g:html_indent_inctags = "html,body,head,tbody" 
    

    See "HTML indenting not working in compiled Vim 7.4, any ideas?" and "alternative html indent script" for more information.

提交回复
热议问题