2 " Language: Shell Script
3 " Maintainer: Nikolai Weibull <now@bitwi.se>
4 " Latest Revision: 2006-04-19
6 if exists("b:did_indent")
11 setlocal indentexpr=GetShIndent()
12 setlocal indentkeys+==then,=do,=else,=elif,=esac,=fi,=fin,=fil,=done
13 setlocal indentkeys-=:,0#
15 if exists("*GetShIndent")
22 function GetShIndent()
23 let lnum = prevnonblank(v:lnum - 1)
28 " Add a 'shiftwidth' after if, while, else, case, until, for, function()
29 " Skip if the line also contains the closure for the above
30 let ind = indent(lnum)
31 let line = getline(lnum)
32 if line =~ '^\s*\(if\|then\|do\|else\|elif\|case\|while\|until\|for\)\>'
33 \ || line =~ '^\s*\<\k\+\>\s*()\s*{'
35 if line !~ '\(esac\|fi\|done\)\>\s*$' && line !~ '}\s*$'
40 " Subtract a 'shiftwidth' on a then, do, else, esac, fi, done
41 " Retain the indentation level if line matches fin (for find)
42 let line = getline(v:lnum)
43 if (line =~ '^\s*\(then\|do\|else\|elif\|esac\|fi\|done\)\>' || line =~ '^\s*}')
44 \ && line !~ '^\s*fi[ln]\>'