How do I fix incorrect inline Javascript indentation in Vim?

后端 未结 9 1560
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-12 15:09

I can\'t seem to get inline Javascript indenting properly in Vim. Consider the following:

  $(document).ready(function() {

  // Closing brace correctly inde         


        
相关标签:
9条回答
  • 2020-12-12 15:38

    The most comprehensive and bug-free Javascript indentation script is the one by Preston Koprivica. The so called OOP script that is in the proposed answer has severe bugs, and does not indent code properly that has square brackets.

    0 讨论(0)
  • 2020-12-12 15:38

    Most of these answers are from 2009 and, frankly, are out of date.

    vim-javascript is much more recent and up-to-date than Preston's script.

    Installation is a bit more complicated if you haven't started using Vundle yet, but it doesn't seem to suffer from the issues of the alternatives.

    0 讨论(0)
  • 2020-12-12 15:40

    I had this same issue. This is the best of all Javascript indentation scripts:

    http://www.vim.org/scripts/script.php?script_id=1840

    It requires the IndentAnything plugin

    http://www.vim.org/scripts/script.php?script_id=1839

    As an added bonus, I wrote this indent script that will make Javascript blocks quite pretty. It uses the default html indenter by default (and the IndentAnything one when within a Javascript block)

    http://gist.github.com/371902

    0 讨论(0)
提交回复
热议问题