如何修复 Vim 中不正确的内联 Javascript 缩进? [英] How do I fix incorrect inline Javascript indentation in Vim?

查看:20
本文介绍了如何修复 Vim 中不正确的内联 Javascript 缩进?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法在 Vim 中正确地进行内联 Javascript 缩进.考虑以下几点:

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

  $(document).ready(function() {

  // Closing brace correctly indented
    $("input").focus(function() {
      $(this).closest("li").addClass("cur-focus");
    }); // <-- I had to manually unindent this

  // Closing brace incorrectly indented
    $("input").blur(function() {
      $(this).closest("li").removeClass("cur-focus");
      }); // <-- This is what it does by default. Argh!

  });

Vim 似乎坚持自动缩进第二个案例中显示的右大括号.如果我重新缩进整个文件,它也会这样做.如何使用第一种情况中看到的更标准的 JS 缩进样式让它自动缩进?

Vim seems to insist on automatically indenting the closing brace shown in the second case there. It does the same if I re-indent the whole file. How do I get it to automatically indent using the more standard JS indenting style seen in the first case?

推荐答案

使用 JavaScript 缩进:Preston Koprivica 的 JavaScript 缩进(包括 HTML 缩进).感谢 oligofren 的提醒 - 给他一个赞成票.

Use JavaScript Indent: Javascript indenter (HTML indent is included) by Preston Koprivica. Thanks for the heads-up from oligofren - give him an up-vote.

这篇关于如何修复 Vim 中不正确的内联 Javascript 缩进?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆