diff options
Diffstat (limited to 'ftplugin')
| -rw-r--r-- | ftplugin/kotlin.vim | 2 | ||||
| -rw-r--r-- | ftplugin/nix.vim | 13 | ||||
| -rw-r--r-- | ftplugin/plantuml.vim | 19 | ||||
| -rw-r--r-- | ftplugin/terraform.vim | 195 | 
4 files changed, 162 insertions, 67 deletions
| diff --git a/ftplugin/kotlin.vim b/ftplugin/kotlin.vim index 417f0824..519a153a 100644 --- a/ftplugin/kotlin.vim +++ b/ftplugin/kotlin.vim @@ -2,7 +2,7 @@ if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'kotlin') != -1    finish  endif -if exists("b:did_ftplugin") | finish | endif +if exists('b:did_ftplugin') | finish | endif  let b:did_ftplugin = 1  setlocal comments=:// diff --git a/ftplugin/nix.vim b/ftplugin/nix.vim index 900ee683..c80b825a 100644 --- a/ftplugin/nix.vim +++ b/ftplugin/nix.vim @@ -12,11 +12,14 @@ if (exists("b:did_ftplugin"))  endif  let b:did_ftplugin = 1 -  setlocal -    \ comments=:# -    \ commentstring=#\ %s +  \ comments=:# +  \ commentstring=#\ %s +  \ iskeyword+=- + +if get(g:, 'nix_recommended_style', 1) +  setlocal      \ shiftwidth=2      \ softtabstop=2 -    \ expandtab -    \ iskeyword+=- +    \ expandtab  +endif diff --git a/ftplugin/plantuml.vim b/ftplugin/plantuml.vim index 9fe82d5e..535fd0b9 100644 --- a/ftplugin/plantuml.vim +++ b/ftplugin/plantuml.vim @@ -2,12 +2,18 @@ if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'plantuml') != -1    finish  endif +scriptencoding utf-8 +" Vim filetype plugin file +" Language:     PlantUML +" Maintainer:   Anders Thøgersen <first name at bladre dot dk> +" License:      VIM LICENSE +  if exists('b:loaded_plantuml_plugin')    finish  endif  let b:loaded_plantuml_plugin = 1 -let s:cpo_save = &cpo -set cpo&vim +let s:cpo_save = &cpoptions +set cpoptions&vim  if !exists('g:plantuml_executable_script')    let g:plantuml_executable_script='plantuml' @@ -21,10 +27,13 @@ if exists('loaded_matchit')          \ ',\<rnote\>:\<endrnote\>' .          \ ',\<hnote\>:\<endhnote\>' .          \ ',\<title\>:\<endtitle\>' . -        \ ',\<\while\>:\<endwhile\>' +        \ ',\<\while\>:\<endwhile\>' . +        \ ',@startuml:@enduml'  endif -let &l:makeprg=g:plantuml_executable_script . ' ' .  fnameescape(expand('%')) +if get(g:, 'plantuml_set_makeprg', 1) +  let &l:makeprg=g:plantuml_executable_script . ' %' +endif  setlocal comments=s1:/',mb:',ex:'/,:' commentstring=/'%s'/ formatoptions-=t formatoptions+=croql @@ -33,5 +42,5 @@ let b:endwise_words = 'loop,group,alt,note,legend'  let b:endwise_pattern = '^\s*\zs\<\(loop\|group\|alt\|note\ze[^:]*$\|legend\)\>.*$'  let b:endwise_syngroups = 'plantumlKeyword' -let &cpo = s:cpo_save +let &cpoptions = s:cpo_save  unlet s:cpo_save diff --git a/ftplugin/terraform.vim b/ftplugin/terraform.vim index 0ece8bf6..fd4c2be0 100644 --- a/ftplugin/terraform.vim +++ b/ftplugin/terraform.vim @@ -5,71 +5,154 @@ endif  " terraform.vim - basic vim/terraform integration  " Maintainer: HashiVim <https://github.com/hashivim> -set formatoptions-=t - -if exists("g:loaded_terraform") || v:version < 700 || &cp || !executable('terraform') +if exists('b:did_ftplugin') || v:version < 700 || &compatible    finish  endif -let g:loaded_terraform = 1 +let b:did_ftplugin = 1 + +let s:cpo_save = &cpoptions + +setlocal formatoptions-=t +let b:undo_ftplugin = 'setlocal formatoptions<' + +" 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<' + +set cpoptions&vim + +if !exists('g:terraform_align') +  let g:terraform_align = 0 +endif + +if !exists('g:terraform_remap_spacebar') +  let g:terraform_remap_spacebar = 0 +endif + +if !exists('g:terraform_fold_sections') +  let g:terraform_fold_sections = 0 +endif + +if g:terraform_align && exists(':Tabularize') +  inoremap <buffer> <silent> = =<Esc>:call <SID>terraformalign()<CR>a +  function! s:terraformalign() +    let p = '^.*=[^>]*$' +    if exists(':Tabularize') && getline('.') =~# '^.*=' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p) +      let column = strlen(substitute(getline('.')[0:col('.')],'[^=]','','g')) +      let position = strlen(matchstr(getline('.')[0:col('.')],'.*=\s*\zs.*')) +      Tabularize/=/l1 +      normal! 0 +      call search(repeat('[^=]*=',column).'\s\{-\}'.repeat('.',position),'ce',line('.')) +    endif +  endfunction +endif + +if g:terraform_fold_sections +  function! TerraformFolds() +    let thisline = getline(v:lnum) +    if match(thisline, '^resource') >= 0 +      return '>1' +    elseif match(thisline, '^provider') >= 0 +      return '>1' +    elseif match(thisline, '^module') >= 0 +      return '>1' +    elseif match(thisline, '^variable') >= 0 +      return '>1' +    elseif match(thisline, '^output') >= 0 +      return '>1' +    elseif match(thisline, '^data') >= 0 +      return '>1' +    elseif match(thisline, '^terraform') >= 0 +      return '>1' +    elseif match(thisline, '^locals') >= 0 +      return '>1' +    else +      return '=' +    endif +  endfunction +  setlocal foldmethod=expr +  setlocal foldexpr=TerraformFolds() +  setlocal foldlevel=1 +  let b:undo_ftplugin .= ' foldmethod< foldexpr< foldlevel<' + +  function! TerraformFoldText() +    let foldsize = (v:foldend-v:foldstart) +    return getline(v:foldstart).' ('.foldsize.' lines)' +  endfunction +  setlocal foldtext=TerraformFoldText() +  let b:undo_ftplugin .= ' foldtext<' +endif + +" Re-map the space bar to fold and unfold +if get(g:, 'terraform_remap_spacebar', 1) +  "inoremap <space> <C-O>za +  nnoremap <space> za +  onoremap <space> <C-C>za +  vnoremap <space> zf +endif -if !exists("g:terraform_fmt_on_save") || !filereadable(expand("%:p")) +" Set the commentstring +if exists('g:terraform_commentstring') +    let &l:commentstring=g:terraform_commentstring +else +    setlocal commentstring=#%s +endif +let b:undo_ftplugin .= ' commentstring<' + +if !exists('g:terraform_fmt_on_save')    let g:terraform_fmt_on_save = 0  endif  function! s:commands(A, L, P) -  return join([ -  \ "apply", -  \ "console", -  \ "destroy", -  \ "env", -  \ "fmt", -  \ "get", -  \ "graph", -  \ "import", -  \ "init", -  \ "output", -  \ "plan", -  \ "providers", -  \ "push", -  \ "refresh", -  \ "show", -  \ "taint", -  \ "untaint", -  \ "validate", -  \ "version", -  \ "workspace", -  \ "debug", -  \ "force-unlock", -  \ "state" -  \ ], "\n") +  return [ +  \ 'apply', +  \ 'console', +  \ 'destroy', +  \ 'env', +  \ 'fmt', +  \ 'get', +  \ 'graph', +  \ 'import', +  \ 'init', +  \ 'output', +  \ 'plan', +  \ 'providers', +  \ 'push', +  \ 'refresh', +  \ 'show', +  \ 'taint', +  \ 'untaint', +  \ 'validate', +  \ 'version', +  \ 'workspace', +  \ '0.12checklist', +  \ 'debug', +  \ 'force-unlock', +  \ 'state' +  \ ]  endfunction -" Adapted from vim-hclfmt: -" https://github.com/fatih/vim-hclfmt/blob/master/autoload/fmt.vim -function! terraform#fmt() -  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 +let &cpoptions = s:cpo_save +unlet s:cpo_save -augroup terraform -  autocmd! -  autocmd BufEnter * -        \ command! -nargs=+ -complete=custom,s:commands Terraform execute '!terraform '.<q-args>. ' -no-color' -  autocmd BufEnter * command! -nargs=0 TerraformFmt call terraform#fmt() -  if get(g:, "terraform_fmt_on_save", 1) +if !executable('terraform') +  finish +endif + +let s:cpo_save = &cpoptions + +command! -nargs=+ -complete=customlist,s:commands -buffer Terraform execute '!terraform '.<q-args>. ' -no-color' +command! -nargs=0 -buffer TerraformFmt call terraform#fmt() +let b:undo_ftplugin .= '|delcommand Terraform|delcommand TerraformFmt' + +if get(g:, 'terraform_fmt_on_save', 1) +  augroup terraform +    autocmd!      autocmd BufWritePre *.tf call terraform#fmt()      autocmd BufWritePre *.tfvars call terraform#fmt() -  endif -augroup END +  augroup END +endif + +let &cpoptions = s:cpo_save +unlet s:cpo_save | 
