-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscss_indent.vim
executable file
·37 lines (36 loc) · 979 Bytes
/
scss_indent.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
" usage:
" set indentexpr=scss_indent#GetIndent(v:lnum)
fun! scss_indent#GetIndent(lnum)
" { -> increase indent
" } -> decrease indent
if a:lnum == 1
" start at 0 indentation
return 0
endif
" try to find last line ending with { or }
" ignoring // comments
let regex = '\([{}]\)\%(\/\/.*\)\?$'
let nr = search(regex, 'bnW')
if nr > 0
let last = indent(nr)
let m = matchlist(getline(nr), regex)
let m_curr = matchlist(getline(a:lnum), regex)
echoe string(m).string(m_curr)
if !empty(m_curr) && m_curr[1] == '}' && m[1] == '{'
" last was open, current is close, use same indent
return last
elseif !empty(m_curr) && m_curr[1] == '}' && m[1] == '}'
" } line and last line was }: decrease
return last - &sw
endif
if m[1] == '{'
" line after {: increase indent
return last + &sw
else
" line after } or { - same indent
return last
endif
else
return 0
endif
endfun