1" Vim indent file 2" Language: reStructuredText Documentation Format 3" Maintainer: Nikolai Weibull <[email protected]> 4" Latest Revision: 2005-06-29 5 6if exists("b:did_indent") 7 finish 8endif 9let b:did_indent = 1 10 11setlocal indentexpr=GetRSTIndent() 12setlocal indentkeys=!^F,o,O 13 14if exists("*GetRSTIndent") 15 finish 16endif 17 18function GetRSTIndent() 19 let lnum = prevnonblank(v:lnum - 1) 20 if lnum == 0 21 return 0 22 endif 23 24 let ind = indent(lnum) 25 let line = getline(lnum) 26 27 if line =~ '^\s*[-*+]\s' 28 let ind = ind + 2 29 elseif line =~ '^\s*\d\+.\s' 30 let ind = ind + matchend(substitute(line, '^\s*', '', ''), '\d\+.\s\+') 31 endif 32 33 let line = getline(v:lnum - 1) 34 35 if line =~ '^\s*$' 36 execute lnum 37 call search('^\s*\%([-*+]\s\|\d\+.\s\|\.\.\|$\)', 'bW') 38 let line = getline('.') 39 if line =~ '^\s*[-*+]' 40 let ind = ind - 2 41 elseif line =~ '^\s*\d\+\.\s' 42 let ind = ind - matchend(substitute(line, '^\s*', '', ''), 43 \ '\d\+\.\s\+') 44 elseif line =~ '^\s*\.\.' 45 let ind = ind - 3 46 else 47 let ind = ind 48 endif 49 endif 50 51 return ind 52endfunction 53