暫無描述

sls.vim 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. " Slow yaml highlighting workaround
  2. if exists('+regexpengine') && ('&regexpengine' == 0)
  3. setlocal regexpengine=1
  4. endif
  5. " Use two-spaces for indentation
  6. setlocal expandtab
  7. setlocal softtabstop=2
  8. setlocal shiftwidth=2
  9. setlocal commentstring=#%s
  10. setlocal formatoptions=crl
  11. " r -> don't add comment leader after an Enter
  12. " c -> wrap long comments, including #
  13. " l -> do not wrap long lines
  14. " indentation
  15. setlocal autoindent
  16. " This function is from https://gist.github.com/871107
  17. " Author: Ian Young
  18. "
  19. function! GetYamlIndent()
  20. let cnum = v:lnum
  21. let lnum = v:lnum - 1
  22. if lnum == 0
  23. return 0
  24. endif
  25. let line = substitute(getline(lnum),'\s\+$','','')
  26. let cline = substitute(getline(cnum),'\s\+$','','')
  27. let indent = indent(lnum)
  28. let increase = indent + &sw
  29. let decrease = indent - &sw
  30. if line =~ ':$'
  31. return increase
  32. elseif line !~ ':$' && cline =~ ':$'
  33. return decrease
  34. elseif line =~ ':$'
  35. else
  36. return indent
  37. endif
  38. endfunction
  39. setlocal indentexpr=GetYamlIndent()
  40. " folding
  41. setlocal foldmethod=indent
  42. setlocal foldlevel=6 " by default do not fold
  43. " Visual warning about UTF8 characters in SLS file.
  44. " salt does not like them much, so they should be red
  45. augroup utfsls
  46. autocmd!
  47. highlight UTFsls ctermbg=red guibg=red
  48. match UTFsls /[\x7F-\xFF]/
  49. autocmd BufWinEnter <buffer> match UTFsls /[\x7F-\xFF]/
  50. autocmd InsertEnter <buffer> match UTFsls /[\x7F-\xFF]/
  51. autocmd InsertLeave <buffer> match UTFsls /[\x7F-\xFF]/
  52. autocmd BufWinLeave <buffer> call clearmatches()
  53. augroup END