Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7539347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:21:27+00:00 2026-05-30T07:21:27+00:00

Auto formatting ( gg=G ) works perfectly for code like so (example from here

  • 0

Auto formatting (gg=G) works perfectly for code like so (example from here):

fun()
{
for(...)
{
for(...)
{
if(...)
{
}
}
}
}

becomes

fun()
{
  for(...)
  {
    for(...)
    {
      if(...)
      {
      }
    }
  }
}

but it fails for more complex code like so (copied from here)

<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
});
});
</script>
</head>

<body>
<p>If you click on me, I will disappear.</p>
</body>

</html>

becomes:

<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $("p").click(function(){
      $(this).hide();
      });
    });
</script>
</head>

<body>
<p>If you click on me, I will disappear.</p>
</body>

</html>

Why is the, for example, <p> tag not indented in the body? Is this a shortcoming of vim’s formatter or am I using it incorrectly?

EDIT: Thank you to everyone who mentioned I should put filetype plugin indent on in my .vimrc file. That made indenting a lot better. However, it is still failing sometimes. observe (copied from here)

<!DOCTYPE html>
<html>
  <body>

    <div style="text-align:center">
      <button onclick="playPause()">Play/Pause</button>
      <button onclick="makeBig()">Big</button>
      <button onclick="makeSmall()">Small</button>
      <button onclick="makeNormal()">Normal</button>
      <br />
      <video id="video1">
      <source src="mov_bbb.mp4" type="video/mp4" />
      <source src="mov_bbb.ogg" type="video/ogg" />
      Your browser does not support HTML5 video.
      </video>
    </div>

    <script type="text/javascript">
      var myVideo=document.getElementById("video1");

function playPause()
{
  if (myVideo.paused)
    myVideo.play();
  else
    myVideo.pause();
}

function makeBig()
{
  myVideo.height=(myVideo.videoHeight*2);
}

function makeSmall()
{
  myVideo.height=(myVideo.videoHeight/2);
}

function makeNormal()
{
  myVideo.height=(myVideo.videoHeight);
}
</script>

<p>Video courtesy of <a href="http://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>

</body>
</html>

doesn’t change at all. It doesn’t realize that those functions are nested inside the <script> tag. Setting the filetype to js.html or html.js does not help either

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:21:28+00:00Added an answer on May 30, 2026 at 7:21 am

    So vim has different formatting/syntax highlighting options for different filetypes. You can read about it here. So for your regular c++ file the indenting is pretty standard so it normally gets it correct but for your html file you might have different perferences then the pereson who made the format file. You can edit and look at your formatting configuration in linux under ~/.vim/ftplugin and the html file will be called html.vim.

    Also like bill says you may need to turn on the filetype plugin by either setting it in your ~/.vimrc or enabling it by typing :filetype plugin indent on

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Eclipse keeps auto formatting upon save, for example: it is insisting the following code
I really like IDEA's code formatting, but how do I get it to reformat
Is there any way to change Visual Studio Auto formatting options? Like VS by
We would like to be able to reformat C++ blocks/functions of code directly from
Does an auto-formatting tool exist for vi that'll allow me to define per language
How can I disable auto formatting for views (html files) in vs2008?
I've got a problem with the formatting of inline code blocks within the VS2010
Does Dreamweaver CS5 support auto-formatting feature similar to Visual Studio 2010 CTRL + K
Just curious if the XAML editor is any better at auto-formatting and wrapping attributes
Duplicate: VS2008 Removes my Indentation in .js file (Turn off auto formatting in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.