dotfiles

My personal home directory config files
git clone https://erai.gay/code/dotfiles/
Log | Files | Refs | LICENSE

omiltem.vim (826B)


      1 if exists("b:did_indent")
      2 	finish
      3 endif
      4 let b:did_indent = 1
      5 
      6 setlocal autoindent
      7 setlocal indentexpr=OmiltemIndent(v:lnum)
      8 setlocal indentkeys+=0=},0=)
      9 
     10 let b:undo_indent = "setlocal autoindent< indentexpr< indentkeys<"
     11 
     12 if exists('*OmiltemIndent')
     13 	finish
     14 endif
     15 
     16 function! OmiltemIndent(lnum)
     17 	let l:prevlnum = prevnonblank(a:lnum-1)
     18 	if l:prevlnum == 0
     19 		return 0
     20 	endif
     21 
     22 	" Strip comments
     23 	let l:prevl = substitute(getline(l:prevlnum), '//.*$', '', '')
     24 	let l:thisl = substitute(getline(a:lnum), '//.*$', '', '')
     25 
     26 	" Match the previous indentation
     27 	let l:ind = indent(l:prevlnum)
     28 
     29 	" Increase indentation after opening a block
     30 	if l:prevl =~ '[({]\s*$'
     31 		let l:ind += shiftwidth()
     32 	endif
     33 
     34 	" Decrease indentation when closing a block
     35 	if l:thisl =~ '^\s*[)}]'
     36 		let l:ind -= shiftwidth()
     37 	endif
     38 
     39 	return l:ind
     40 endfunction