How can I format JS code in Vim?

前端 未结 7 1861
半阙折子戏
半阙折子戏 2020-12-14 08:19

I have this bit of JavaScript...

 15   $(\'.ajax_edit_address\').each(function() {
 16     $(this).ajaxForm({
 17       target: $(this).parents(\'table.addre         


        
7条回答
  •  轮回少年
    2020-12-14 09:12

    The biggest issue seems to be the cindent doesn't recognize this type of syntax:

    test({
      var b = 2;
    });
    

    It will turn it into this:

    test({
        var b = 2;
        });
    

    If you handle that case I'd imagine the indent wouldn't be so awful for the jQuery syntax. But this would require you writing a custom javascript indent file. Also, you'd have to edit the html indent file to not use cindent for script tags with javascript content.

    I don't think anyone has successfully created a jquery/prototype compatible indent file for javascript. The existing javascript indent scripts are all flawed.

提交回复
热议问题