我似乎无法在Vim中正确地进行内联Javascript缩进.考虑以下:
$(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!
});
Run Code Online (Sandbox Code Playgroud)
Vim似乎坚持自动缩进第二种情况下所示的闭合支撑.如果我重新缩进整个文件,它也会这样做.如何使用第一种情况下看到的更标准的JS缩进样式自动缩进?
oli*_*ren 85
最全面和无错误的 Javascript缩进脚本是Preston Koprivica的脚本.建议的答案中所谓的OOP脚本有严重的错误,并且没有正确缩进具有方括号的代码.
Cha*_*per 82
使用JavaScript缩进: Preston Koprivica的Javascript压头(包括HTML缩进).感谢来自寡头的单挑 - 给他一个投票.
Kri*_*amp 17
上面提到的脚本没有正确地格式化jQuery中经常使用的闭包语法:
$(function() {
// only one level of indentation, not two
});
Run Code Online (Sandbox Code Playgroud)
这个脚本对我来说效果更好:http://www.vim.org/scripts/script.php?script_id = 2765
Cor*_*ein 10
这些答案大多来自2009年,坦白说,已经过时了.
vim-javascript比Preston的脚本更新,更新.
如果你还没有开始使用Vundle,安装会有点复杂,但它似乎没有替代品的问题.
也许这些设置的某些组合应该在您的VIMRC文件中.
syntax on
set syn=auto
set showmatch
filetype on
filetype plugin on
filetype indent on
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
Run Code Online (Sandbox Code Playgroud)