Permalink
Browse files

curly brace-based scss indentation

  • Loading branch information...
1 parent f9c9106 commit 9dcce02bad5d68500298152e241b9c3488219546 @dbushong committed Mar 2, 2012
Showing with 39 additions and 0 deletions.
  1. +39 −0 dot.vim/indent/scss.vim
@@ -0,0 +1,39 @@
+" from http://stackoverflow.com/questions/4829244/how-do-i-define-indents-in-vim-based-on-curly-braces
+
+if exists("b:did_indent")
+ finish
+endif
+let b:did_indent = 1
+
+setlocal indentexpr=GetMyIndent()
+function! GetMyIndent()
+ let cline = getline(v:lnum)
+
+ " Find a non-blank line above the current line.
+ let lnum = prevnonblank(v:lnum - 1)
+ " Hit the start of the file, use zero indent.
+ if lnum == 0
+ return 0
+ endif
+ let line = getline(lnum)
+ let ind = indent(lnum)
+
+ " Indent blocks enclosed by {}, (), or []
+ " Find a real opening brace
+ let bracepos = match(line, '[(){}\[\]]', matchend(line, '^\s*[)}\]]'))
+ while bracepos != -1
+ let brace = strpart(line, bracepos, 1)
+ if brace == '(' || brace == '{' || brace == '['
+ let ind = ind + &sw
+ else
+ let ind = ind - &sw
+ endif
+ let bracepos = match(line, '[(){}\[\]]', bracepos + 1)
+ endwhile
+ let bracepos = matchend(cline, '^\s*[)}\]]')
+ if bracepos != -1
+ let ind = ind - &sw
+ endif
+
+ return ind
+endfunction

0 comments on commit 9dcce02

Please sign in to comment.