summaryrefslogtreecommitdiffstats
path: root/autoload/terraform.vim
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2019-06-08 12:44:15 +0200
committerAdam Stankiewicz <sheerun@sher.pl>2019-06-08 12:44:15 +0200
commit671078ef6c851b688b63165761cec82f9f6e03f7 (patch)
treeefde30baaf2ca21a09a35e1ccf1d2ff744482d2b /autoload/terraform.vim
parentaebef2c2e76b88384b1121c237c965e8cf8b3bcb (diff)
downloadvim-polyglot-671078ef6c851b688b63165761cec82f9f6e03f7.tar.gz
vim-polyglot-671078ef6c851b688b63165761cec82f9f6e03f7.zip
Update
Diffstat (limited to 'autoload/terraform.vim')
-rw-r--r--autoload/terraform.vim25
1 files changed, 25 insertions, 0 deletions
diff --git a/autoload/terraform.vim b/autoload/terraform.vim
new file mode 100644
index 00000000..210ee59f
--- /dev/null
+++ b/autoload/terraform.vim
@@ -0,0 +1,25 @@
+if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'terraform') != -1
+ finish
+endif
+
+" Adapted from vim-hclfmt:
+" https://github.com/fatih/vim-hclfmt/blob/master/autoload/fmt.vim
+function! terraform#fmt()
+ if !filereadable(expand('%:p'))
+ return
+ endif
+ let l:curw = winsaveview()
+ let l:tmpfile = tempname() . '.tf'
+ call writefile(getline(1, '$'), l:tmpfile)
+ let output = system('terraform fmt -write ' . l:tmpfile)
+ if v:shell_error == 0
+ try | silent undojoin | catch | endtry
+ call rename(l:tmpfile, resolve(expand('%')))
+ silent edit!
+ let &syntax = &syntax
+ else
+ echo output
+ call delete(l:tmpfile)
+ endif
+ call winrestview(l:curw)
+endfunction