vim, right way to indent css and js inside html

心已入冬 提交于 2019-12-31 02:33:12

问题


Couldn't find proper solution in old questions, so

    <!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
        <style type="text/css">
body, input{
    background-color:red;
}
        </style>
        <script>
function test() {
    return false
}
        </script>
    </head>
    <body>
        <div></div>
    </body>
</html>

everything except code inside <style> and <script> tags indented ok, how can I fix it?


回答1:


I use othree/html5.vim plugin which supports css/javascript inside html. It works although this isn't probably the simplest solution.

Your code is indented like this:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <style type="text/css">
      body, input{
        background-color:red;
      }
    </style>
    <script>
      function test() {
        return false
      }
    </script>
  </head>
  <body>
    <div></div>
  </body>
</html>



回答2:


As it turns out: That this has been done on purpose! Even my current Vim 8.1 installation contains an indent/html.vim-file which has such zero-indentation as its default setting.

That is however configurable via vimrc with:

let g:html_indent_script1 = "inc" 
let g:html_indent_style1 = "inc" 

...and -shame on us- is also mentioned in :help html-indent



来源:https://stackoverflow.com/questions/34967130/vim-right-way-to-indent-css-and-js-inside-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!