vim-polyglot/ftplugin/terraform.vim

77 lines
2.2 KiB
VimL
Raw Normal View History

if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'terraform') != -1
finish
endif
2018-10-08 13:00:59 -04:00
" terraform.vim - basic vim/terraform integration
" Maintainer: HashiVim <https://github.com/hashivim>
2019-06-08 06:44:15 -04:00
if exists('b:did_ftplugin') || v:version < 700 || &compatible
2018-10-08 13:00:59 -04:00
finish
endif
2019-06-08 06:44:15 -04:00
let b:did_ftplugin = 1
let s:cpo_save = &cpoptions
set cpoptions&vim
2019-07-01 10:25:37 -04:00
" j is a relatively recent addition; silence warnings when setting it.
setlocal formatoptions-=t formatoptions+=croql
silent! setlocal formatoptions+=j
let b:undo_ftplugin = 'setlocal formatoptions<'
2019-06-08 06:44:15 -04:00
2019-07-01 10:25:37 -04:00
if !has('patch-7.4.1142')
" Include hyphens as keyword characters so that a keyword appearing as
" part of a longer name doesn't get partially highlighted.
setlocal iskeyword+=-
let b:undo_ftplugin .= ' iskeyword<'
2019-06-08 06:44:15 -04:00
endif
2019-07-01 10:25:37 -04:00
if get(g:, 'terraform_fold_sections', 0)
2019-06-08 06:44:15 -04:00
setlocal foldmethod=expr
2019-07-01 10:25:37 -04:00
setlocal foldexpr=terraform#folds()
2019-06-08 06:44:15 -04:00
setlocal foldlevel=1
2019-07-01 10:25:37 -04:00
setlocal foldtext=terraform#foldText()
let b:undo_ftplugin .= ' foldmethod< foldexpr< foldlevel< foldtext<'
2019-06-08 06:44:15 -04:00
endif
2018-10-08 13:00:59 -04:00
2019-06-08 06:44:15 -04:00
" Set the commentstring
2019-07-01 10:25:37 -04:00
let &l:commentstring = get(g:, 'terraform_commentstring', '#%s')
2019-06-08 06:44:15 -04:00
let b:undo_ftplugin .= ' commentstring<'
2019-07-01 10:25:37 -04:00
" Re-map the space bar to fold and unfold
if get(g:, 'terraform_remap_spacebar', 0)
nnoremap <buffer> <space> za
onoremap <buffer> <space> <C-C>za
vnoremap <buffer> <space> zf
let b:undo_ftplugin .= '|unmap <buffer> <space>'
2018-10-08 13:00:59 -04:00
endif
2019-07-01 10:25:37 -04:00
if get(g:, 'terraform_align', 0) && exists(':Tabularize')
inoremap <buffer> <silent> = =<Esc>:call terraform#align()<CR>a
let b:undo_ftplugin .= '|iunmap <buffer> ='
endif
2018-10-08 13:00:59 -04:00
2019-06-08 06:44:15 -04:00
let &cpoptions = s:cpo_save
unlet s:cpo_save
2018-10-08 13:00:59 -04:00
2019-06-08 06:44:15 -04:00
if !executable('terraform')
finish
endif
let s:cpo_save = &cpoptions
2019-07-01 10:25:37 -04:00
set cpoptions&vim
2019-06-08 06:44:15 -04:00
2019-07-01 10:25:37 -04:00
command! -nargs=+ -complete=customlist,terraform#commands -buffer Terraform execute '!terraform '.<q-args>. ' -no-color'
2019-06-08 06:44:15 -04:00
command! -nargs=0 -buffer TerraformFmt call terraform#fmt()
let b:undo_ftplugin .= '|delcommand Terraform|delcommand TerraformFmt'
2019-07-01 10:25:37 -04:00
if get(g:, 'terraform_fmt_on_save', 0)
augroup vim.terraform.fmt
2019-06-08 06:44:15 -04:00
autocmd!
2018-10-08 13:00:59 -04:00
autocmd BufWritePre *.tf call terraform#fmt()
autocmd BufWritePre *.tfvars call terraform#fmt()
2019-06-08 06:44:15 -04:00
augroup END
endif
let &cpoptions = s:cpo_save
unlet s:cpo_save