sshconfig.vim 796 B

1234567891011121314151617181920212223242526272829303132333435
  1. " Vim indent file
  2. " Language: ssh config file
  3. " Maintainer: JasonKim <git@jasonk.me>
  4. " Last Change: 2020 May 16
  5. if exists("b:did_indent")
  6. finish
  7. endif
  8. let b:did_indent = 1
  9. setlocal autoindent
  10. setlocal indentexpr=GetSshconfigIndent(v:lnum)
  11. setlocal indentkeys=o,O,*<Return>,0=~host\ ,0=~match\ ,0#,!^F
  12. let b:undo_indent = "setlocal autoindent< indentexpr< indentkeys<"
  13. if exists("*GetSshconfigIndent")
  14. finish
  15. endif
  16. function GetSshconfigIndent(lnum)
  17. let sw = shiftwidth()
  18. let prev_lnum = prevnonblank(a:lnum - 1)
  19. let curr_lnum = a:lnum
  20. let prev_line = getline(prev_lnum)
  21. let curr_line = getline(curr_lnum)
  22. if curr_line =~? '^\s*\(host\|match\)\s'
  23. return 0
  24. elseif prev_line =~? '^\s*\(host\|match\)\s'
  25. return sw
  26. else
  27. return indent(prev_lnum)
  28. endif
  29. endfunction