Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion indent/javascript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let b:indented = 0
let b:in_comment = 0

setlocal indentexpr=GetJsIndent()
setlocal indentkeys+==},=),=],0=*/,0=/*,0=\,,0=;,*<Return>
setlocal indentkeys+==},=),=],0=*/,0=/*,0=\,,0=\.,0=;,*<Return>
if exists("*GetJsIndent")
finish
endif
Expand All @@ -50,6 +50,9 @@ let s:expr_comment_end = 'c\*/'
let s:expr_comma_start = '^\s*,'
let s:expr_var = '^\s*var\s'
let s:expr_var_stop = ';'

let s:expr_op_start = '^\s*\(\.\|+ \|&&\|||\)'

" add $ to Fix
" ;(function() {
" something;
Expand Down Expand Up @@ -175,6 +178,24 @@ function! DoIndent(ind, str, pline)
endif
endif

" a
" .foo <-
" .bar <-
if (match(line, s:expr_op_start) != -1)
if (match(pline, s:expr_op_start) == -1)
let ind = ind + &sw
endif
endif

" a
" .bar
" newline <-
if (match(pline, s:expr_op_start) != -1)
if (match(line, s:expr_op_start) == -1)
let ind = ind - &sw
endif
endif

if (match(line, s:expr_semic_start) != -1 && match(pline, s:expr_comma_start) != -1)
let ind = ind - 2
endif
Expand Down
30 changes: 29 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ var a = a
, b = b
, c = c;

var a = a
, b = c

var a = a
, b = b
;
Expand All @@ -227,10 +230,35 @@ foo({
, c : c
, d : {
e : e
f : f
, f : f
}
, g : {[
h : h
, i : i
]}
});

foo()
.foo
.ff

bar()
.foo
.bar

if( a == b
&& c == d
&& e == f
|| g == h
|| i == j ) {

a = b
+ c
+ d

a = b
+ c
+ d
}