blob: 266878bbdc216f427b952c74afaa2b30882c1574 [file] [log] [blame]
Bram Moolenaar938ae282023-02-20 20:44:55 +00001" Vim syntax file
2" Language: fish
3" Maintainer: Nicholas Boyle (github.com/nickeb96)
4" Repository: https://github.com/nickeb96/fish.vim
5" Last Change: February 1, 2023
6
7if exists("b:current_syntax")
8 finish
9endif
10
11let s:cpo_save = &cpo
12set cpo&vim
13
14
15" Statements
16syn cluster fishStatement contains=fishKeywordAndOr,fishNot,fishSelectStatement,fishKeyword,fishKeywordIf,fishCommand,fishVariable
17
18syn keyword fishKeywordAndOr and or nextgroup=fishNot,fishSelectStatement,fishKeyword,fishKeywordIf,fishCommand
19hi def link fishKeywordAndOr fishOperator
20
21syn keyword fishNot not skipwhite nextgroup=fishSelectStatement,fishKeyword,fishKeywordIf,fishCommand
22syn match fishNot /!/ skipwhite nextgroup=fishSelectStatement,fishKeyword,fishKeywordIf,fishCommand
23hi def link fishNot fishOperator
24
25syn keyword fishSelectStatement command builtin skipwhite nextgroup=fishKeyword,fishKeywordIf,fishCommand,fishOption
26hi def link fishSelectStatement fishKeyword
27
28syn keyword fishKeyword end skipwhite nextgroup=@fishTerminator
29
30syn keyword fishKeywordIf if skipwhite nextgroup=@fishStatement
31syn keyword fishKeyword else skipwhite nextgroup=fishKeywordIf,fishSemicolon
32hi def link fishKeywordIf fishKeyword
33
34syn keyword fishKeyword switch skipwhite nextgroup=@fishArgument
35syn keyword fishKeyword case skipwhite nextgroup=@fishArgument
36
37syn keyword fishKeyword while skipwhite nextgroup=@fishStatement
38
39syn keyword fishKeyword for skipwhite nextgroup=fishForVariable
40syn match fishForVariable /[[:alnum:]_]\+/ contained skipwhite nextgroup=fishKeywordIn
41syn keyword fishKeywordIn in contained skipwhite nextgroup=@fishArgument
42hi def link fishForVariable fishParameter
43hi def link fishKeywordIn fishKeyword
44
45syn keyword fishKeyword _ abbr argparse begin bg bind block break breakpoint cd commandline
46 \ complete continue count disown echo emit eval exec exit false fg function functions
47 \ history jobs math printf pwd random read realpath return set set_color source status
48 \ string test time true type ulimit wait
49 \ skipwhite nextgroup=@fishNext
50syn match fishKeyword /\<contains\>/ skipwhite nextgroup=@fishNext
51
52syn match fishCommand /[[:alnum:]_\/[][[:alnum:]+._-]*/ skipwhite nextgroup=@fishNext
53
54
55" Internally Nested Arguments
56
57syn cluster fishSubscriptArgs contains=fishInnerVariable,fishIndexNum,fishIndexRange,fishInnerCommandSub
58
59syn match fishInnerVariable /\$\+[[:alnum:]_]\+/ contained
60syn match fishInnerVariable /\$\+[[:alnum:]_]\+\[/me=e-1,he=e-1 contained nextgroup=fishInnerSubscript
61hi def link fishInnerVariable fishVariable
62
63syn region fishInnerSubscript matchgroup=fishVariable start=/\[/ end=/]/ contained
64 \ keepend contains=@fishSubscriptArgs
65hi def link fishInnerSubscript fishSubscript
66
67syn match fishIndexNum /[+-]?[[:digit:]]\+/ contained
68hi def link fishIndexNum fishParameter
69
70syn match fishIndexRange /\.\./ contained
71hi def link fishIndexRange fishParameter
72
73syn region fishInnerCommandSub matchgroup=fishOperator start=/(/ start=/\$(/ end=/)/ contained
74 \ contains=@fishStatement
75hi def link fishInnerCommandSub fishCommandSub
76
77syn region fishQuotedCommandSub matchgroup=fishOperator start=/\$(/ end=/)/ contained
78 \ contains=@fishStatement
79hi def link fishQuotedCommandSub fishCommandSub
80
81syn match fishBraceExpansionComma /,/ contained
82hi def link fishBraceExpansionComma fishOperator
83
84syn match fishBracedParameter '[[:alnum:]\u5b\u5d@:=+.%/!_-]\+' contained contains=fishInnerPathGlob
85hi def link fishBracedParameter fishParameter
86
87syn region fishBracedQuote start=/'/ skip=/\\'/ end=/'/ contained
88 \ contains=fishEscapedEscape,fishEscapedSQuote
89syn region fishBracedQuote start=/"/ skip=/\\"/ end=/"/ contained
90 \ contains=fishEscapedEscape,fishEscapedDQuote,fishEscapedDollar,fishInnerVariable,fishInnerCommandSub
91hi def link fishBracedQuote fishQuote
92
93
94" Arguments
95
96syn cluster fishArgument contains=fishParameter,fishOption,fishVariable,fishPathGlob,fishBraceExpansion,fishQuote,fishCharacter,fishCommandSub,fishRedirection,fishSelfPid
97
98syn match fishParameter '[[:alnum:]\u5b\u5d@:=+.,%/!_-]\+' contained skipwhite nextgroup=@fishNext
99
100syn match fishOption /-[[:alnum:]=_-]*/ contained skipwhite nextgroup=@fishNext
101
102syn match fishPathGlob /\(\~\|*\|?\)/ contained skipwhite nextgroup=@fishNext
103
104syn region fishBraceExpansion matchgroup=fishOperator start=/{/ end=/}/ contained
105 \ contains=fishBraceExpansionComma,fishInnerVariable,fishInnerCommandSub,fishBracedParameter,fishBracedQuote
106 \ skipwhite nextgroup=@fishNext
107
108syn match fishVariable /\$\+[[:alnum:]_]\+/ skipwhite nextgroup=@fishNext
109syn match fishVariable /\$\+[[:alnum:]_]\+\[/me=e-1,he=e-1 nextgroup=fishSubscript
110
111syn region fishSubscript matchgroup=fishVariable start=/\[/ end=/]/ contained
112 \ keepend contains=@fishSubscriptArgs
113 \ skipwhite nextgroup=@fishNext
114
115syn region fishCommandSub matchgroup=fishOperator start=/(/ start=/\$(/ end=/)/ contained
116 \ contains=@fishStatement
117 \ skipwhite nextgroup=@fishNext
118
119syn region fishQuote start=/'/ skip=/\\'/ end=/'/ contained
120 \ contains=fishEscapedEscape,fishEscapedSQuote
121 \ skipwhite nextgroup=@fishNext
122syn region fishQuote start=/"/ skip=/\\"/ end=/"/ contained
123 \ contains=fishEscapedEscape,fishEscapedDQuote,fishEscapedDollar,fishInnerVariable,fishQuotedCommandSub
124 \ skipwhite nextgroup=@fishNext
125
126syn match fishEscapedEscape /\\\\/ contained
127syn match fishEscapedSQuote /\\'/ contained
128syn match fishEscapedDQuote /\\"/ contained
129syn match fishEscapedDollar /\\\$/ contained
130hi def link fishEscapedEscape fishCharacter
131hi def link fishEscapedSQuote fishCharacter
132hi def link fishEscapedDQuote fishCharacter
133hi def link fishEscapedDollar fishCharacter
134
135syn match fishCharacter /\\[0-7]\{1,3}/ contained skipwhite nextgroup=@fishNext
136syn match fishCharacter /\\u[0-9a-fA-F]\{4}/ contained skipwhite nextgroup=@fishNext
137syn match fishCharacter /\\U[0-9a-fA-F]\{8}/ contained skipwhite nextgroup=@fishNext
138syn match fishCharacter /\\x[0-7][0-9a-fA-F]\|\\x[0-9a-fA-F]/ contained skipwhite nextgroup=@fishNext
139syn match fishCharacter /\\X[0-9a-fA-F]\{1,2}/ contained skipwhite nextgroup=@fishNext
140syn match fishCharacter /\\[abcefnrtv[\](){}<>\\*?~%#$|&;'" ]/ contained skipwhite nextgroup=@fishNext
141
142syn match fishRedirection /</ contained skipwhite nextgroup=fishRedirectionTarget
143syn match fishRedirection /[0-9&]\?>[>?]\?/ contained skipwhite nextgroup=fishRedirectionTarget
144syn match fishRedirection /[0-9&]\?>&[0-9-]/ contained skipwhite nextgroup=@fishNext
145
146syn match fishRedirectionTarget /[[:alnum:]$~*?{,}"'\/._-]\+/ contained contains=fishInnerVariable skipwhite nextgroup=@fishNext
147hi def link fishRedirectionTarget fishRedirection
148
149syn match fishSelfPid /%self\>/ contained nextgroup=@fishNext
150hi def link fishSelfPid fishOperator
151
152
153" Terminators
154
155syn cluster fishTerminator contains=fishPipe,fishBackgroundJob,fishSemicolon,fishSymbolicAndOr
156
157syn match fishPipe /\(1>\|2>\|&\)\?|/ contained skipwhite nextgroup=@fishStatement
158hi def link fishPipe fishEnd
159
160syn match fishBackgroundJob /&$/ contained skipwhite nextgroup=@fishStatement
161syn match fishBackgroundJob /&[^<>&|]/me=s+1,he=s+1 contained skipwhite nextgroup=@fishStatement
162hi def link fishBackgroundJob fishEnd
163
164syn match fishSemicolon /;/ skipwhite nextgroup=@fishStatement
165hi def link fishSemicolon fishEnd
166
167syn match fishSymbolicAndOr /\(&&\|||\)/ contained skipwhite skipempty nextgroup=@fishStatement
168hi def link fishSymbolicAndOr fishOperator
169
170
171" Other
172
173syn cluster fishNext contains=fishEscapedNl,@fishArgument,@fishTerminator
174
175syn match fishEscapedNl /\\$/ skipnl skipwhite contained nextgroup=@fishNext
176
177syn match fishComment /#.*/ contains=fishTodo,@Spell
178
179syn keyword fishTodo TODO contained
180
181
182
183syn sync minlines=200
184syn sync maxlines=300
185
186
187" Intermediate highlight groups matching $fish_color_* variables
188
189hi def link fishCommand fish_color_command
190hi def link fishComment fish_color_comment
191hi def link fishEnd fish_color_end
192hi def link fishCharacter fish_color_escape
193hi def link fishKeyword fish_color_keyword
194hi def link fishEscapedNl fish_color_normal
195hi def link fishOperator fish_color_operator
196hi def link fishVariable fish_color_operator
197hi def link fishInnerVariable fish_color_operator
198hi def link fishPathGlob fish_color_operator
199hi def link fishOption fish_color_option
200hi def link fishParameter fish_color_param
201hi def link fishQuote fish_color_quote
202hi def link fishRedirection fish_color_redirection
203
204
205" Default highlight groups
206
207hi def link fish_color_param Normal
208hi def link fish_color_normal Normal
209hi def link fish_color_option Normal
210hi def link fish_color_command Function
211hi def link fish_color_keyword Keyword
212hi def link fish_color_end Delimiter
213hi def link fish_color_operator Operator
214hi def link fish_color_redirection Type
215hi def link fish_color_quote String
216hi def link fish_color_escape Character
217hi def link fish_color_comment Comment
218
219hi def link fishTodo Todo
220
221
222let b:current_syntax = 'fish'
223
224let &cpo = s:cpo_save
225unlet s:cpo_save