sed.vim 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. " Vim syntax file
  2. " Language: sed
  3. " Maintainer: Haakon Riiser <hakonrk@fys.uio.no>
  4. " URL: http://folk.uio.no/hakonrk/vim/syntax/sed.vim
  5. " Last Change: 2010 May 29
  6. " quit when a syntax file was already loaded
  7. if exists("b:current_syntax")
  8. finish
  9. endif
  10. syn match sedError "\S"
  11. syn match sedWhitespace "\s\+" contained
  12. syn match sedSemicolon ";"
  13. syn match sedAddress "[[:digit:]$]"
  14. syn match sedAddress "\d\+\~\d\+"
  15. syn region sedAddress matchgroup=Special start="[{,;]\s*/\(\\/\)\="lc=1 skip="[^\\]\(\\\\\)*\\/" end="/I\=" contains=sedTab,sedRegexpMeta
  16. syn region sedAddress matchgroup=Special start="^\s*/\(\\/\)\=" skip="[^\\]\(\\\\\)*\\/" end="/I\=" contains=sedTab,sedRegexpMeta
  17. syn match sedComment "^\s*#.*$"
  18. syn match sedFunction "[dDgGhHlnNpPqQx=]\s*\($\|;\)" contains=sedSemicolon,sedWhitespace
  19. syn match sedLabel ":[^;]*"
  20. syn match sedLineCont "^\(\\\\\)*\\$" contained
  21. syn match sedLineCont "[^\\]\(\\\\\)*\\$"ms=e contained
  22. syn match sedSpecial "[{},!]"
  23. if exists("highlight_sedtabs")
  24. syn match sedTab "\t" contained
  25. endif
  26. " Append/Change/Insert
  27. syn region sedACI matchgroup=sedFunction start="[aci]\\$" matchgroup=NONE end="^.*$" contains=sedLineCont,sedTab
  28. syn region sedBranch matchgroup=sedFunction start="[bt]" matchgroup=sedSemicolon end=";\|$" contains=sedWhitespace
  29. syn region sedRW matchgroup=sedFunction start="[rw]" matchgroup=sedSemicolon end=";\|$" contains=sedWhitespace
  30. " Substitution/transform with various delimiters
  31. syn region sedFlagwrite matchgroup=sedFlag start="w" matchgroup=sedSemicolon end=";\|$" contains=sedWhitespace contained
  32. syn match sedFlag "[[:digit:]gpI]*w\=" contains=sedFlagwrite contained
  33. syn match sedRegexpMeta "[.*^$]" contained
  34. syn match sedRegexpMeta "\\." contains=sedTab contained
  35. syn match sedRegexpMeta "\[.\{-}\]" contains=sedTab contained
  36. syn match sedRegexpMeta "\\{\d\*,\d*\\}" contained
  37. syn match sedRegexpMeta "\\(.\{-}\\)" contains=sedTab contained
  38. syn match sedReplaceMeta "&\|\\\($\|.\)" contains=sedTab contained
  39. " Metacharacters: $ * . \ ^ [ ~
  40. " @ is used as delimiter and treated on its own below
  41. let __at = char2nr("@")
  42. let __sed_i = char2nr(" ") " ASCII: 32, EBCDIC: 64
  43. if has("ebcdic")
  44. let __sed_last = 255
  45. else
  46. let __sed_last = 126
  47. endif
  48. let __sed_metacharacters = '$*.\^[~'
  49. while __sed_i <= __sed_last
  50. let __sed_delimiter = escape(nr2char(__sed_i), __sed_metacharacters)
  51. if __sed_i != __at
  52. exe 'syn region sedAddress matchgroup=Special start=@\\'.__sed_delimiter.'\(\\'.__sed_delimiter.'\)\=@ skip=@[^\\]\(\\\\\)*\\'.__sed_delimiter.'@ end=@'.__sed_delimiter.'I\=@ contains=sedTab'
  53. exe 'syn region sedRegexp'.__sed_i 'matchgroup=Special start=@'.__sed_delimiter.'\(\\\\\|\\'.__sed_delimiter.'\)*@ skip=@[^\\'.__sed_delimiter.']\(\\\\\)*\\'.__sed_delimiter.'@ end=@'.__sed_delimiter.'@me=e-1 contains=sedTab,sedRegexpMeta keepend contained nextgroup=sedReplacement'.__sed_i
  54. exe 'syn region sedReplacement'.__sed_i 'matchgroup=Special start=@'.__sed_delimiter.'\(\\\\\|\\'.__sed_delimiter.'\)*@ skip=@[^\\'.__sed_delimiter.']\(\\\\\)*\\'.__sed_delimiter.'@ end=@'.__sed_delimiter.'@ contains=sedTab,sedReplaceMeta keepend contained nextgroup=sedFlag'
  55. endif
  56. let __sed_i = __sed_i + 1
  57. endwhile
  58. syn region sedAddress matchgroup=Special start=+\\@\(\\@\)\=+ skip=+[^\\]\(\\\\\)*\\@+ end=+@I\=+ contains=sedTab,sedRegexpMeta
  59. syn region sedRegexp64 matchgroup=Special start=+@\(\\\\\|\\@\)*+ skip=+[^\\@]\(\\\\\)*\\@+ end=+@+me=e-1 contains=sedTab,sedRegexpMeta keepend contained nextgroup=sedReplacement64
  60. syn region sedReplacement64 matchgroup=Special start=+@\(\\\\\|\\@\)*+ skip=+[^\\@]\(\\\\\)*\\@+ end=+@+ contains=sedTab,sedReplaceMeta keepend contained nextgroup=sedFlag
  61. " Since the syntax for the substituion command is very similar to the
  62. " syntax for the transform command, I use the same pattern matching
  63. " for both commands. There is one problem -- the transform command
  64. " (y) does not allow any flags. To save memory, I ignore this problem.
  65. syn match sedST "[sy]" nextgroup=sedRegexp\d\+
  66. hi def link sedAddress Macro
  67. hi def link sedACI NONE
  68. hi def link sedBranch Label
  69. hi def link sedComment Comment
  70. hi def link sedDelete Function
  71. hi def link sedError Error
  72. hi def link sedFlag Type
  73. hi def link sedFlagwrite Constant
  74. hi def link sedFunction Function
  75. hi def link sedLabel Label
  76. hi def link sedLineCont Special
  77. hi def link sedPutHoldspc Function
  78. hi def link sedReplaceMeta Special
  79. hi def link sedRegexpMeta Special
  80. hi def link sedRW Constant
  81. hi def link sedSemicolon Special
  82. hi def link sedST Function
  83. hi def link sedSpecial Special
  84. hi def link sedWhitespace NONE
  85. if exists("highlight_sedtabs")
  86. hi def link sedTab Todo
  87. endif
  88. let __sed_i = char2nr(" ") " ASCII: 32, EBCDIC: 64
  89. while __sed_i <= __sed_last
  90. exe "hi def link sedRegexp".__sed_i "Macro"
  91. exe "hi def link sedReplacement".__sed_i "NONE"
  92. let __sed_i = __sed_i + 1
  93. endwhile
  94. unlet __sed_i __sed_last __sed_delimiter __sed_metacharacters
  95. let b:current_syntax = "sed"
  96. " vim: sts=4 sw=4 ts=8