2

我需要帮助让 VIM 在脚本标签内正确缩进 javascript。

这就是我想要的样子:

  <script type="text/javascript">
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-257015-24']);
    _gaq.push(['_trackPageview']);

    (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
  </script>

这就是我让 VIM 缩进时的样子,这很好,但不是最优的:

  <script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-257015-24']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
  </script>

我的 VIM 文件大致是这些:http: //github.com/lunks/vimfiles

我尝试将脚本附加到我想要缩进的标签上vimrc

let g:html_indent_inctags = "body,head,tbody,ul,li,p,script"

但是,虽然它成功地缩进了script标签后面的内容,但它不再将其内容缩进为 javascript,而只是文本。

如何按照我的意图使脚本标签内的 VIM 缩进 Javascript?

4

2 回答 2

0

这个做到了:https ://github.com/vim-scripts/indenthtml.vim

确保添加到您的 vimrc:

let g:html_indent_script1 = "inc"
let g:html_indent_style1 = "inc"
于 2012-06-23T18:09:22.313 回答
0

尝试:set ft=html.javascript或在 vim.org 上为 HTML/JS 搜索更好的缩进文件。

于 2012-06-22T05:48:33.523 回答