install.fairie/dotfiles/.vim/plugged/ansible-vim/indent/ansible.vim
Git E2E Dev Test Username 8a6af30c98 git subrepo clone https://github.com/pearofducks/ansible-vim.git ./dotfiles/.vim/plugged/ansible-vim
subrepo:
  subdir:   "dotfiles/.vim/plugged/ansible-vim"
  merged:   "93798e8c8"
upstream:
  origin:   "https://github.com/pearofducks/ansible-vim.git"
  branch:   "master"
  commit:   "93798e8c8"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"
2022-10-18 10:37:50 -04:00

63 lines
1.6 KiB
VimL

let s:save_cpo = &cpo
set cpo&vim
setlocal indentexpr=GetAnsibleIndent(v:lnum)
setlocal indentkeys=!^F,o,O,0#,0},0],<:>,-,*<Return>
setlocal nosmartindent
setlocal expandtab
setlocal softtabstop=2
setlocal shiftwidth=2
setlocal commentstring=#%s
setlocal formatoptions+=cl
" c -> wrap long comments, including #
" l -> do not wrap long lines
let s:comment = '\v^\s*#' " # comment
let s:array_entry = '\v^\s*-\s' " - foo
let s:named_module_entry = '\v^\s*-\s*(name|hosts|role):\s*\S' " - name: 'do stuff'
let s:dictionary_entry = '\v^\s*[^:-]+:\s*$' " with_items:
let s:key_value = '\v^\s*[^:-]+:\s*\S' " apt: name=package
let s:scalar_value = '\v:\s*[>|\|]\s*$' " shell: >
let s:blank = '\v^\s*$' " line with only spaces
if exists('*GetAnsibleIndent')
finish
endif
function GetAnsibleIndent(lnum)
if a:lnum == 1 || !prevnonblank(a:lnum-1)
return 0
endif
if exists("g:ansible_unindent_after_newline")
if (a:lnum -1) != prevnonblank(a:lnum - 1)
return 0
endif
endif
let prevlnum = prevnonblank(a:lnum - 1)
let default = GetYAMLIndent(a:lnum)
let increase = indent(prevlnum) + &sw
let prevline = getline(prevlnum)
let line = getline(a:lnum)
if line !~ s:blank
return default " we only special case blank lines
elseif prevline =~ s:array_entry
if prevline =~ s:named_module_entry
return increase
else
return default
endif
elseif prevline =~ s:dictionary_entry
return increase
elseif prevline =~ s:key_value
if prevline =~ s:scalar_value
return increase
else
return default
endif
else
return default
endif
endfunction
let &cpo = s:save_cpo