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