sass.vim 926 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. " Vim indent file
  2. " Language: Sass
  3. " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
  4. " Last Change: 2023 Dec 28
  5. if exists("b:did_indent")
  6. finish
  7. endif
  8. let b:did_indent = 1
  9. setlocal autoindent
  10. setlocal indentexpr=GetSassIndent()
  11. setlocal indentkeys=o,O,*<Return>,<:>,!^F
  12. let b:undo_indent = "setl ai< inde< indk<"
  13. " Only define the function once.
  14. if exists("*GetSassIndent")
  15. finish
  16. endif
  17. let s:property = '^\s*:\|^\s*[[:alnum:]#{}-]\+\%(:\|\s*=\)'
  18. let s:extend = '^\s*\%(@extend\|@include\|+\)'
  19. function! GetSassIndent()
  20. let lnum = prevnonblank(v:lnum-1)
  21. let line = substitute(getline(lnum),'\s\+$','','')
  22. let cline = substitute(substitute(getline(v:lnum),'\s\+$','',''),'^\s\+','','')
  23. let line = substitute(line,'^\s\+','','')
  24. let indent = indent(lnum)
  25. if line !~ s:property && line !~ s:extend && cline =~ s:property
  26. return indent + shiftwidth()
  27. else
  28. return -1
  29. endif
  30. endfunction
  31. " vim:set sw=2: