3 " Author: Alecs King <alecsk@gmail.com>
5 " inspired by indent/lua.vim
8 " just indent common cases to avoid manually typing tab or backspace
10 " for better style, please use gofmt after done editing.
12 " since it just simply uses regex matches,
13 " there might be some mis-indented corner cases.
16 " Only load this indent file when no other was loaded.
17 if exists("b:did_indent")
22 " 4-space hard tabs is the preferred style for Go
28 setlocal indentexpr=GetGoIndent()
30 " To make Vim call GetLuaIndent() when it finds '\s*)', '\s*}', '\s*case', '\s*default'
31 setlocal indentkeys+=0=),0=},0=case,0=default
35 " Only define the function once.
36 if exists("*GetGoIndent")
40 function! GetGoIndent()
41 " Find a non-blank line above the current line.
42 let prevlnum = prevnonblank(v:lnum - 1)
44 " Hit the start of the file, use zero indent.
49 " Add a 'shiftwidth' after lines that start a block:
50 " 'case', 'default', '{', '('
51 let ind = indent(prevlnum)
52 let prevline = getline(prevlnum)
53 let midx = match(prevline, '^\s*\%(case\>\|default\>\)')
55 let midx = match(prevline, '[({]\s*$')
58 let ind = ind + &shiftwidth
61 " Subtract a 'shiftwidth' on 'case', 'default', '}', ')'.
62 " This is the part that requires 'indentkeys'.
63 let midx = match(getline(v:lnum), '^\s*\%(case\>\|default\>\|[)}]\)')
65 let ind = ind - &shiftwidth