summaryrefslogtreecommitdiffstats
path: root/indent/terraform.vim
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2019-07-01 16:25:37 +0200
committerAdam Stankiewicz <sheerun@sher.pl>2019-07-01 16:25:37 +0200
commit140430ffb73d5e0851ba2df2abd29106b1677687 (patch)
tree686fc28a75cbcdddbfad4a2e93f0433614d182bc /indent/terraform.vim
parentd52700284984ada048ce325404dfa25237271ba1 (diff)
downloadvim-polyglot-140430ffb73d5e0851ba2df2abd29106b1677687.tar.gz
vim-polyglot-140430ffb73d5e0851ba2df2abd29106b1677687.zip
Update
Diffstat (limited to 'indent/terraform.vim')
-rw-r--r--indent/terraform.vim21
1 files changed, 8 insertions, 13 deletions
diff --git a/indent/terraform.vim b/indent/terraform.vim
index 2a0e5799..74b7808a 100644
--- a/indent/terraform.vim
+++ b/indent/terraform.vim
@@ -34,24 +34,19 @@ function! TerraformIndent(lnum)
return 0
endif
- " Previous non-blank line should continue the indent level
+ " Usual case is to continue at the same indent as the previous non-blank line.
let prevlnum = prevnonblank(a:lnum-1)
+ let thisindent = indent(prevlnum)
- " Previous line without comments should continue the indent level
- let prevline = substitute(getline(prevlnum), '//.*$', '', '')
- let previndent = indent(prevlnum)
- let thisindent = previndent
-
- " Config block starting with [ { ( should increase the indent level
- if prevline =~# '[\[{\(]\s*$'
+ " If that previous line is a non-comment ending in [ { (, increase the
+ " indent level.
+ let prevline = getline(prevlnum)
+ if prevline !~# '^\s*\(#\|//\)' && prevline =~# '[\[{\(]\s*$'
let thisindent += &shiftwidth
endif
- " Current line without comments should continue the indent level
- let thisline = substitute(getline(a:lnum), '//.*$', '', '')
-
- " Config block ending with ) } ] should get the indentation
- " level from the initial config block
+ " If the current line ends a block, decrease the indent level.
+ let thisline = getline(a:lnum)
if thisline =~# '^\s*[\)}\]]'
let thisindent -= &shiftwidth
endif