kdl.vim 819 B

12345678910111213141516171819202122232425262728293031
  1. " Vim indent file
  2. " Language: KDL
  3. " Author: Aram Drevekenin <aram@poor.dev>
  4. " Maintainer: Yinzuo Jiang <jiangyinzuo@foxmail.com>
  5. " Last Change: 2024-06-16
  6. " Only load this indent file when no other was loaded.
  7. if exists("b:did_indent")
  8. finish
  9. endif
  10. let b:did_indent = 1
  11. setlocal indentexpr=KdlIndent()
  12. let b:undo_indent = "setlocal indentexpr<"
  13. function! KdlIndent(...)
  14. let line = substitute(getline(v:lnum), '//.*$', '', '')
  15. let previousNum = prevnonblank(v:lnum - 1)
  16. let previous = substitute(getline(previousNum), '//.*$', '', '')
  17. let l:indent = indent(previousNum)
  18. if previous =~ "{" && previous !~ "}"
  19. let l:indent += shiftwidth()
  20. endif
  21. if line =~ "}" && line !~ "{"
  22. let l:indent -= shiftwidth()
  23. endif
  24. return l:indent
  25. endfunction
  26. " vim: sw=2 sts=2 et