tcsh.vim 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. " Vim indent file
  2. " Language: C-shell (tcsh)
  3. " Maintainer: GI <a@b.c>, where a='gi1242+vim', b='gmail', c='com'
  4. " Last Modified: Sat 10 Dec 2011 09:23:00 AM EST
  5. " Only load this indent file when no other was loaded.
  6. if exists("b:did_indent")
  7. finish
  8. endif
  9. let b:did_indent = 1
  10. setlocal indentexpr=TcshGetIndent()
  11. setlocal indentkeys+=e,0=end,0=endsw indentkeys-=0{,0},0),:,0#
  12. " Only define the function once.
  13. if exists("*TcshGetIndent")
  14. finish
  15. endif
  16. function TcshGetIndent()
  17. " Find a non-blank line above the current line.
  18. let lnum = prevnonblank(v:lnum - 1)
  19. " Hit the start of the file, use zero indent.
  20. if lnum == 0
  21. return 0
  22. endif
  23. " Add indent if previous line begins with while or foreach
  24. " OR line ends with case <str>:, default:, else, then or \
  25. let ind = indent(lnum)
  26. let line = getline(lnum)
  27. if line =~ '\v^\s*%(while|foreach)>|^\s*%(case\s.*:|default:|else)\s*$|%(<then|\\)$'
  28. let ind = ind + shiftwidth()
  29. endif
  30. if line =~ '\v^\s*breaksw>'
  31. let ind = ind - shiftwidth()
  32. endif
  33. " Subtract indent if current line has on end, endif, case commands
  34. let line = getline(v:lnum)
  35. if line =~ '\v^\s*%(else|end|endif)\s*$'
  36. let ind = ind - shiftwidth()
  37. endif
  38. return ind
  39. endfunction