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
7 " For version 5.x: Clear all syntax items
8 " For version 6.x: Quit when a syntax file was already loaded
11 elseif exists("b:current_syntax")
15 syn match sedError "\S"
17 syn match sedWhitespace "\s\+" contained
18 syn match sedSemicolon ";"
19 syn match sedAddress "[[:digit:]$]"
20 syn match sedAddress "\d\+\~\d\+"
21 syn region sedAddress matchgroup=Special start="[{,;]\s*/\(\\/\)\="lc=1 skip="[^\\]\(\\\\\)*\\/" end="/I\=" contains=sedTab,sedRegexpMeta
22 syn region sedAddress matchgroup=Special start="^\s*/\(\\/\)\=" skip="[^\\]\(\\\\\)*\\/" end="/I\=" contains=sedTab,sedRegexpMeta
23 syn match sedComment "^\s*#.*$"
24 syn match sedFunction "[dDgGhHlnNpPqQx=]\s*\($\|;\)" contains=sedSemicolon,sedWhitespace
25 syn match sedLabel ":[^;]*"
26 syn match sedLineCont "^\(\\\\\)*\\$" contained
27 syn match sedLineCont "[^\\]\(\\\\\)*\\$"ms=e contained
28 syn match sedSpecial "[{},!]"
29 if exists("highlight_sedtabs")
30 syn match sedTab "\t" contained
33 " Append/Change/Insert
34 syn region sedACI matchgroup=sedFunction start="[aci]\\$" matchgroup=NONE end="^.*$" contains=sedLineCont,sedTab
36 syn region sedBranch matchgroup=sedFunction start="[bt]" matchgroup=sedSemicolon end=";\|$" contains=sedWhitespace
37 syn region sedRW matchgroup=sedFunction start="[rw]" matchgroup=sedSemicolon end=";\|$" contains=sedWhitespace
39 " Substitution/transform with various delimiters
40 syn region sedFlagwrite matchgroup=sedFlag start="w" matchgroup=sedSemicolon end=";\|$" contains=sedWhitespace contained
41 syn match sedFlag "[[:digit:]gpI]*w\=" contains=sedFlagwrite contained
42 syn match sedRegexpMeta "[.*^$]" contained
43 syn match sedRegexpMeta "\\." contains=sedTab contained
44 syn match sedRegexpMeta "\[.\{-}\]" contains=sedTab contained
45 syn match sedRegexpMeta "\\{\d\*,\d*\\}" contained
46 syn match sedRegexpMeta "\\(.\{-}\\)" contains=sedTab contained
47 syn match sedReplaceMeta "&\|\\\($\|.\)" contains=sedTab contained
49 " Metacharacters: $ * . \ ^ [ ~
50 " @ is used as delimiter and treated on its own below
51 let __at = char2nr("@")
52 let __sed_i = char2nr(" ") " ASCII: 32, EBCDIC: 64
58 let __sed_metacharacters = '$*.\^[~'
59 while __sed_i <= __sed_last
60 let __sed_delimiter = escape(nr2char(__sed_i), __sed_metacharacters)
62 exe 'syn region sedAddress matchgroup=Special start=@\\'.__sed_delimiter.'\(\\'.__sed_delimiter.'\)\=@ skip=@[^\\]\(\\\\\)*\\'.__sed_delimiter.'@ end=@'.__sed_delimiter.'I\=@ contains=sedTab'
63 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
64 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'
66 let __sed_i = __sed_i + 1
68 syn region sedAddress matchgroup=Special start=+\\@\(\\@\)\=+ skip=+[^\\]\(\\\\\)*\\@+ end=+@I\=+ contains=sedTab,sedRegexpMeta
69 syn region sedRegexp64 matchgroup=Special start=+@\(\\\\\|\\@\)*+ skip=+[^\\@]\(\\\\\)*\\@+ end=+@+me=e-1 contains=sedTab,sedRegexpMeta keepend contained nextgroup=sedReplacement64
70 syn region sedReplacement64 matchgroup=Special start=+@\(\\\\\|\\@\)*+ skip=+[^\\@]\(\\\\\)*\\@+ end=+@+ contains=sedTab,sedReplaceMeta keepend contained nextgroup=sedFlag
72 " Since the syntax for the substituion command is very similar to the
73 " syntax for the transform command, I use the same pattern matching
74 " for both commands. There is one problem -- the transform command
75 " (y) does not allow any flags. To save memory, I ignore this problem.
76 syn match sedST "[sy]" nextgroup=sedRegexp\d\+
78 if version >= 508 || !exists("did_sed_syntax_inits")
80 let did_sed_syntax_inits = 1
81 command -nargs=+ HiLink hi link <args>
83 command -nargs=+ HiLink hi def link <args>
86 HiLink sedAddress Macro
88 HiLink sedBranch Label
89 HiLink sedComment Comment
90 HiLink sedDelete Function
93 HiLink sedFlagwrite Constant
94 HiLink sedFunction Function
96 HiLink sedLineCont Special
97 HiLink sedPutHoldspc Function
98 HiLink sedReplaceMeta Special
99 HiLink sedRegexpMeta Special
100 HiLink sedRW Constant
101 HiLink sedSemicolon Special
102 HiLink sedST Function
103 HiLink sedSpecial Special
104 HiLink sedWhitespace NONE
105 if exists("highlight_sedtabs")
108 let __sed_i = char2nr(" ") " ASCII: 32, EBCDIC: 64
109 while __sed_i <= __sed_last
110 exe "HiLink sedRegexp".__sed_i "Macro"
111 exe "HiLink sedReplacement".__sed_i "NONE"
112 let __sed_i = __sed_i + 1
118 unlet __sed_i __sed_last __sed_delimiter __sed_metacharacters
120 let b:current_syntax = "sed"
122 " vim: sts=4 sw=4 ts=8