diff options
Diffstat (limited to 'indent/terraform.vim')
-rw-r--r-- | indent/terraform.vim | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/indent/terraform.vim b/indent/terraform.vim index 5a29dfb4..9a081ff8 100644 --- a/indent/terraform.vim +++ b/indent/terraform.vim @@ -1,13 +1,13 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'terraform') == -1 +" Only load this file if no other indent file was loaded if exists("b:did_indent") finish endif - let b:did_indent = 1 setlocal nolisp -setlocal autoindent +setlocal autoindent sw=2 ts=2 setlocal indentexpr=TerraformIndent(v:lnum) setlocal indentkeys+=<:>,0=},0=) @@ -16,29 +16,30 @@ if exists("*TerraformIndent") endif function! TerraformIndent(lnum) - " previous non-blank line - let prevlnum = prevnonblank(a:lnum-1) - - " beginning of file? - if prevlnum == 0 + " Beginning of the file should have no indent + if a:lnum == 0 return 0 endif - " previous line without comments + " Previous non-blank line should continue the indent level + let prevlnum = prevnonblank(a:lnum-1) + + " Previous line without comments should continue the indent level let prevline = substitute(getline(prevlnum), '//.*$', '', '') let previndent = indent(prevlnum) let thisindent = previndent - " block open? + " Config block starting with [ { ( should increase the indent level if prevline =~ '[\[{\(]\s*$' let thisindent += &sw endif - " current line without comments + " Current line without comments should continue the indent level let thisline = substitute(getline(a:lnum), '//.*$', '', '') - " block close? - if thisline =~ '^\s*[\)\]}]' + " Config block ending with ) } ] should get the indentation + " level from the initial config block + if thisline =~ '^\s*[\)}\]]' let thisindent -= &sw endif |