tcsh.vim 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. " Vim indent file
  2. " Language: C-shell (tcsh)
  3. " Maintainer: Doug Kearns <dougkearns@gmail.com>
  4. " Previous Maintainer: Gautam Iyer <gi1242+vim@NoSpam.com> where NoSpam=gmail (Original Author)
  5. " Last Change: 2021 Oct 15
  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=TcshGetIndent()
  12. setlocal indentkeys+=e,0=end
  13. setlocal indentkeys-=0{,0},0),:,0#
  14. let b:undo_indent = "setl inde< indk<"
  15. " Only define the function once.
  16. if exists("*TcshGetIndent")
  17. finish
  18. endif
  19. function TcshGetIndent()
  20. " Find a non-blank line above the current line.
  21. let lnum = prevnonblank(v:lnum - 1)
  22. " Hit the start of the file, use zero indent.
  23. if lnum == 0
  24. return 0
  25. endif
  26. " Add indent if previous line begins with while or foreach
  27. " OR line ends with case <str>:, default:, else, then or \
  28. let ind = indent(lnum)
  29. let line = getline(lnum)
  30. if line =~ '\v^\s*%(while|foreach)>|^\s*%(case\s.*:|default:|else)\s*$|%(<then|\\)$'
  31. let ind = ind + shiftwidth()
  32. endif
  33. if line =~ '\v^\s*breaksw>'
  34. let ind = ind - shiftwidth()
  35. endif
  36. " Subtract indent if current line has on end, endif, endsw, case commands
  37. let line = getline(v:lnum)
  38. if line =~ '\v^\s*%(else|end|endif|endsw)\s*$'
  39. let ind = ind - shiftwidth()
  40. endif
  41. return ind
  42. endfunction