6

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?

2

2 Answers 2

8

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

Sign up to request clarification or add additional context in comments.

3 Comments

This answer needs to be at the top of the internet. I spent more than an hour trying to figure out how to do this thing that must be simple. Turns out it is simple!
Wait no...It works for style tags, but it indents javascript incorrectly unless I put all of the code inside the tags within {}. Do you not see this?
But it should. I found a bug report and made a change request here: github.com/vim/vim/issues/3205
3

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.