vb.vim 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. " Vim indent file
  2. " Language: VisualBasic (ft=vb) / Basic (ft=basic) / SaxBasic (ft=vb)
  3. " Author: Johannes Zellner <johannes@zellner.org>
  4. " Last Change: Fri, 18 Jun 2004 07:22:42 CEST
  5. " Small update 2010 Jul 28 by Maxim Kim
  6. if exists("b:did_indent")
  7. finish
  8. endif
  9. let b:did_indent = 1
  10. setlocal autoindent
  11. setlocal indentexpr=VbGetIndent(v:lnum)
  12. setlocal indentkeys&
  13. setlocal indentkeys+==~else,=~elseif,=~end,=~wend,=~case,=~next,=~select,=~loop,<:>
  14. let b:undo_indent = "set ai< indentexpr< indentkeys<"
  15. " Only define the function once.
  16. if exists("*VbGetIndent")
  17. finish
  18. endif
  19. fun! VbGetIndent(lnum)
  20. " labels and preprocessor get zero indent immediately
  21. let this_line = getline(a:lnum)
  22. let LABELS_OR_PREPROC = '^\s*\(\<\k\+\>:\s*$\|#.*\)'
  23. if this_line =~? LABELS_OR_PREPROC
  24. return 0
  25. endif
  26. " Find a non-blank line above the current line.
  27. " Skip over labels and preprocessor directives.
  28. let lnum = a:lnum
  29. while lnum > 0
  30. let lnum = prevnonblank(lnum - 1)
  31. let previous_line = getline(lnum)
  32. if previous_line !~? LABELS_OR_PREPROC
  33. break
  34. endif
  35. endwhile
  36. " Hit the start of the file, use zero indent.
  37. if lnum == 0
  38. return 0
  39. endif
  40. let ind = indent(lnum)
  41. " Add
  42. if previous_line =~? '^\s*\<\(begin\|\%(\%(private\|public\|friend\)\s\+\)\=\%(function\|sub\|property\)\|select\|case\|default\|if\|else\|elseif\|do\|for\|while\|enum\|with\)\>'
  43. let ind = ind + shiftwidth()
  44. endif
  45. " Subtract
  46. if this_line =~? '^\s*\<end\>\s\+\<select\>'
  47. if previous_line !~? '^\s*\<select\>'
  48. let ind = ind - 2 * shiftwidth()
  49. else
  50. " this case is for an empty 'select' -- 'end select'
  51. " (w/o any case statements) like:
  52. "
  53. " select case readwrite
  54. " end select
  55. let ind = ind - shiftwidth()
  56. endif
  57. elseif this_line =~? '^\s*\<\(end\|else\|elseif\|until\|loop\|next\|wend\)\>'
  58. let ind = ind - shiftwidth()
  59. elseif this_line =~? '^\s*\<\(case\|default\)\>'
  60. if previous_line !~? '^\s*\<select\>'
  61. let ind = ind - shiftwidth()
  62. endif
  63. endif
  64. return ind
  65. endfun
  66. " vim:sw=4