blob: 27c6417fd0616ca968de94a52867734c5b80e2e1 [file] [log] [blame]
Bram Moolenaara7241f52008-06-24 20:39:31 +00001" tcsh.vim: Vim syntax file for tcsh scripts
Bram Moolenaar6e649222021-10-04 21:32:54 +01002" Maintainer: Doug Kearns <dougkearns@NoSpam.com> where NoSpam=gmail
3" Author: Gautam Iyer <gi1242+vim@NoSpam.com> where NoSpam=gmail
4" Modified: Sun 26 Sep 2021 12:40:55 PM EDT
Bram Moolenaar071d4272004-06-13 20:20:40 +00005"
6" Description: We break up each statement into a "command" and an "end" part.
7" All groups are either a "command" or part of the "end" of a statement (ie
8" everything after the "command"). This is because blindly highlighting tcsh
9" statements as keywords caused way too many false positives. Eg:
10"
Bram Moolenaara83c3e02006-03-17 23:10:44 +000011" set history=200
Bram Moolenaar071d4272004-06-13 20:20:40 +000012"
13" causes history to come up as a keyword, which we want to avoid.
14
15" Quit when a syntax file was already loaded
Bram Moolenaara7241f52008-06-24 20:39:31 +000016if exists('b:current_syntax')
Bram Moolenaar071d4272004-06-13 20:20:40 +000017 finish
18endif
19
Bram Moolenaara7241f52008-06-24 20:39:31 +000020let s:oldcpo = &cpo
21set cpo&vim " Line continuation is used
22
23setlocal iskeyword+=-
24
Bram Moolenaar071d4272004-06-13 20:20:40 +000025syn case match
26
27" ----- Clusters -----
28syn cluster tcshModifiers contains=tcshModifier,tcshModifierError
29syn cluster tcshQuoteList contains=tcshDQuote,tcshSQuote,tcshBQuote
Bram Moolenaara7241f52008-06-24 20:39:31 +000030syn cluster tcshStatementEnds contains=@tcshQuoteList,tcshComment,@tcshVarList,tcshRedir,tcshMeta,tcshHereDoc,tcshSpecial,tcshArguement
31syn cluster tcshStatements contains=tcshBuiltin,tcshCommands,tcshIf,tcshWhile
Bram Moolenaar071d4272004-06-13 20:20:40 +000032syn cluster tcshVarList contains=tcshUsrVar,tcshArgv,tcshSubst
Bram Moolenaara7241f52008-06-24 20:39:31 +000033syn cluster tcshConditions contains=tcshCmdSubst,tcshParenExpr,tcshOperator,tcshNumber,@tcshVarList
34
35" ----- Errors -----
36" Define first, so can be easily overridden.
37syn match tcshError contained '\v\S.+'
Bram Moolenaar071d4272004-06-13 20:20:40 +000038
39" ----- Statements -----
40" Tcsh commands: Any filename / modifiable variable (must be first!)
41syn match tcshCommands '\v[a-zA-Z0-9\\./_$:-]+' contains=tcshSpecial,tcshUsrVar,tcshArgv,tcshVarError nextgroup=tcshStatementEnd
42
Bram Moolenaara7241f52008-06-24 20:39:31 +000043" Builtin commands except those treated specially. Currently (un)set(env),
44" (un)alias, if, while, else, bindkey
45syn keyword tcshBuiltin nextgroup=tcshStatementEnd alloc bg break breaksw builtins bye case cd chdir complete continue default dirs echo echotc end endif endsw eval exec exit fg filetest foreach getspath getxvers glob goto hashstat history hup inlib jobs kill limit log login logout ls ls-F migrate newgrp nice nohup notify onintr popd printenv pushd rehash repeat rootnode sched setpath setspath settc setty setxvers shift source stop suspend switch telltc time umask uncomplete unhash universe unlimit ver wait warp watchlog where which
Bram Moolenaar071d4272004-06-13 20:20:40 +000046
Bram Moolenaara7241f52008-06-24 20:39:31 +000047" StatementEnd is anything after a built-in / command till the lexical end of a
Bram Moolenaar071d4272004-06-13 20:20:40 +000048" statement (;, |, ||, |&, && or end of line)
Bram Moolenaara7241f52008-06-24 20:39:31 +000049syn region tcshStatementEnd transparent contained matchgroup=tcshBuiltin start='' end='\v\\@<!(;|\|[|&]?|\&\&|$)' contains=@tcshStatementEnds
Bram Moolenaar071d4272004-06-13 20:20:40 +000050
51" set expressions (Contains shell variables)
52syn keyword tcshShellVar contained afsuser ampm argv autocorrect autoexpand autolist autologout backslash_quote catalog cdpath color colorcat command complete continue continue_args correct cwd dextract dirsfile dirstack dspmbyte dunique echo echo_style edit ellipsis fignore filec gid group histchars histdup histfile histlit history home ignoreeof implicitcd inputmode killdup killring listflags listjobs listlinks listmax listmaxrows loginsh logout mail matchbeep nobeep noclobber noding noglob nokanji nonomatch nostat notify oid owd path printexitvalue prompt prompt2 prompt3 promptchars pushdtohome pushdsilent recexact recognize_only_executables rmstar rprompt savedirs savehist sched shell shlvl status symlinks tcsh term time tperiod tty uid user verbose version visiblebell watch who wordchars
Bram Moolenaara7241f52008-06-24 20:39:31 +000053syn keyword tcshBuiltin nextgroup=tcshSetEnd set unset
54syn region tcshSetEnd contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$\|;' contains=tcshShellVar,@tcshStatementEnds
Bram Moolenaar071d4272004-06-13 20:20:40 +000055
Bram Moolenaara7241f52008-06-24 20:39:31 +000056" setenv expressions (Contains environment variables)
Bram Moolenaar071d4272004-06-13 20:20:40 +000057syn keyword tcshEnvVar contained AFSUSER COLUMNS DISPLAY EDITOR GROUP HOME HOST HOSTTYPE HPATH LANG LC_CTYPE LINES LS_COLORS MACHTYPE NOREBIND OSTYPE PATH PWD REMOTEHOST SHLVL SYSTYPE TERM TERMCAP USER VENDOR VISUAL
Bram Moolenaara7241f52008-06-24 20:39:31 +000058syn keyword tcshBuiltin nextgroup=tcshEnvEnd setenv unsetenv
59syn region tcshEnvEnd contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$\|;' contains=tcshEnvVar,@tcshStatementEnds
Bram Moolenaar071d4272004-06-13 20:20:40 +000060
61" alias and unalias (contains special aliases)
Bram Moolenaar9964e462007-05-05 17:54:07 +000062syn keyword tcshAliases contained beepcmd cwdcmd jobcmd helpcommand periodic precmd postcmd shell
Bram Moolenaara7241f52008-06-24 20:39:31 +000063syn keyword tcshBuiltin nextgroup=tcshAliCmd skipwhite alias unalias
Bram Moolenaar5c736222010-01-06 20:54:52 +010064syn match tcshAliCmd contained nextgroup=tcshAliEnd skipwhite '\v(\w|-)+' contains=tcshAliases
Bram Moolenaara7241f52008-06-24 20:39:31 +000065syn region tcshAliEnd contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$\|;' contains=@tcshStatementEnds
Bram Moolenaar071d4272004-06-13 20:20:40 +000066
Bram Moolenaara7241f52008-06-24 20:39:31 +000067" if statements
68syn keyword tcshIf nextgroup=tcshIfEnd skipwhite if
69syn region tcshIfEnd contained start='\S' skip='\\$' matchgroup=tcshBuiltin end='\v<then>|$' contains=@tcshConditions,tcshSpecial,@tcshStatementEnds
70syn region tcshIfEnd contained matchgroup=tcshBuiltin contains=@tcshConditions,tcshSpecial start='(' end='\v\)%(\s+then>)?' skipwhite nextgroup=@tcshStatementEnds
71syn region tcshIfEnd contained matchgroup=tcshBuiltin contains=tcshCommands,tcshSpecial start='\v\{\s+' end='\v\s+\}%(\s+then>)?' skipwhite nextgroup=@tcshStatementEnds keepend
Bram Moolenaar071d4272004-06-13 20:20:40 +000072
Bram Moolenaara7241f52008-06-24 20:39:31 +000073" else statements
74syn keyword tcshBuiltin nextgroup=tcshIf skipwhite else
Bram Moolenaar071d4272004-06-13 20:20:40 +000075
76" while statements (contains expressions / operators)
Bram Moolenaara7241f52008-06-24 20:39:31 +000077syn keyword tcshBuiltin nextgroup=@tcshConditions,tcshSpecial skipwhite while
78
79" Conditions (for if and while)
80syn region tcshParenExpr contained contains=@tcshConditions,tcshSpecial matchgroup=tcshBuiltin start='(' end=')'
81syn region tcshCmdSubst contained contains=tcshCommands matchgroup=tcshBuiltin start='\v\{\s+' end='\v\s+\}' keepend
82
83" Bindkey. Internal editor functions
84syn keyword tcshBindkeyFuncs contained backward-char backward-delete-char
85 \ backward-delete-word backward-kill-line backward-word
86 \ beginning-of-line capitalize-word change-case
87 \ change-till-end-of-line clear-screen complete-word
88 \ complete-word-fwd complete-word-back complete-word-raw
89 \ copy-prev-word copy-region-as-kill dabbrev-expand delete-char
90 \ delete-char-or-eof delete-char-or-list
91 \ delete-char-or-list-or-eof delete-word digit digit-argument
92 \ down-history downcase-word end-of-file end-of-line
93 \ exchange-point-and-mark expand-glob expand-history expand-line
94 \ expand-variables forward-char forward-word
95 \ gosmacs-transpose-chars history-search-backward
96 \ history-search-forward insert-last-word i-search-fwd
97 \ i-search-back keyboard-quit kill-line kill-region
98 \ kill-whole-line list-choices list-choices-raw list-glob
99 \ list-or-eof load-average magic-space newline normalize-path
100 \ normalize-command overwrite-mode prefix-meta quoted-insert
101 \ redisplay run-fg-editor run-help self-insert-command
102 \ sequence-lead-in set-mark-command spell-word spell-line
103 \ stuff-char toggle-literal-history transpose-chars
104 \ transpose-gosling tty-dsusp tty-flush-output tty-sigintr
105 \ tty-sigquit tty-sigtsusp tty-start-output tty-stop-output
106 \ undefined-key universal-argument up-history upcase-word
107 \ vi-beginning-of-next-word vi-add vi-add-at-eol vi-chg-case
108 \ vi-chg-meta vi-chg-to-eol vi-cmd-mode vi-cmd-mode-complete
109 \ vi-delprev vi-delmeta vi-endword vi-eword vi-char-back
110 \ vi-char-fwd vi-charto-back vi-charto-fwd vi-insert
111 \ vi-insert-at-bol vi-repeat-char-fwd vi-repeat-char-back
112 \ vi-repeat-search-fwd vi-repeat-search-back vi-replace-char
113 \ vi-replace-mode vi-search-back vi-search-fwd vi-substitute-char
114 \ vi-substitute-line vi-word-back vi-word-fwd vi-undo vi-zero
115 \ which-command yank yank-pop e_copy_to_clipboard
116 \ e_paste_from_clipboard e_dosify_next e_dosify_prev e_page_up
117 \ e_page_down
118syn keyword tcshBuiltin nextgroup=tcshBindkeyEnd bindkey
119syn region tcshBindkeyEnd contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$' contains=@tcshQuoteList,tcshComment,@tcshVarList,tcshMeta,tcshSpecial,tcshArguement,tcshBindkeyFuncs
Bram Moolenaar071d4272004-06-13 20:20:40 +0000120
121" Expressions start with @.
Bram Moolenaara7241f52008-06-24 20:39:31 +0000122syn match tcshExprStart '\v\@\s+' nextgroup=tcshExprVar
123syn match tcshExprVar contained '\v\h\w*%(\[\d+\])?' contains=tcshShellVar,tcshEnvVar nextgroup=tcshExprOp
124syn match tcshExprOp contained '++\|--'
125syn match tcshExprOp contained '\v\s*\=' nextgroup=tcshExprEnd
126syn match tcshExprEnd contained '\v.*$'hs=e+1 contains=@tcshConditions
127syn match tcshExprEnd contained '\v.{-};'hs=e contains=@tcshConditions
Bram Moolenaar071d4272004-06-13 20:20:40 +0000128
129" ----- Comments: -----
Bram Moolenaar9964e462007-05-05 17:54:07 +0000130syn match tcshComment '#\s.*' contains=tcshTodo,tcshCommentTi,@Spell
131syn match tcshComment '\v#($|\S.*)' contains=tcshTodo,tcshCommentTi
132syn match tcshSharpBang '^#! .*$'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000133syn match tcshCommentTi contained '\v#\s*\u\w*(\s+\u\w*)*:'hs=s+1 contains=tcshTodo
Bram Moolenaar071d4272004-06-13 20:20:40 +0000134syn match tcshTodo contained '\v\c<todo>'
135
136" ----- Strings -----
137" Tcsh does not allow \" in strings unless the "backslash_quote" shell
138" variable is set. Set the vim variable "tcsh_backslash_quote" to 0 if you
139" want VIM to assume that no backslash quote constructs exist.
140
141" Backquotes are treated as commands, and are not contained in anything
Bram Moolenaara7241f52008-06-24 20:39:31 +0000142if(exists('tcsh_backslash_quote') && tcsh_backslash_quote == 0)
143 syn region tcshSQuote keepend contained start="\v\\@<!'" end="'"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000144 syn region tcshDQuote keepend contained start='\v\\@<!"' end='"' contains=@tcshVarList,tcshSpecial,@Spell
145 syn region tcshBQuote keepend start='\v\\@<!`' end='`' contains=@tcshStatements
146else
Bram Moolenaara7241f52008-06-24 20:39:31 +0000147 syn region tcshSQuote contained start="\v\\@<!'" skip="\v\\\\|\\'" end="'"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000148 syn region tcshDQuote contained start='\v\\@<!"' end='"' contains=@tcshVarList,tcshSpecial,@Spell
149 syn region tcshBQuote keepend matchgroup=tcshBQuoteGrp start='\v\\@<!`' skip='\v\\\\|\\`' end='`' contains=@tcshStatements
150endif
151
152" ----- Variables -----
153" Variable Errors. Must come first! \$ constructs will be flagged by
154" tcshSpecial, so we don't consider them here.
155syn match tcshVarError '\v\$\S*' contained
156
157" Modifiable Variables without {}.
Bram Moolenaara7241f52008-06-24 20:39:31 +0000158syn match tcshUsrVar contained '\v\$\h\w*%(\[\d+%(-\d+)?\])?' nextgroup=@tcshModifiers contains=tcshShellVar,tcshEnvVar
159syn match tcshArgv contained '\v\$%(\d+|\*)' nextgroup=@tcshModifiers
Bram Moolenaar071d4272004-06-13 20:20:40 +0000160
161" Modifiable Variables with {}.
Bram Moolenaara7241f52008-06-24 20:39:31 +0000162syn match tcshUsrVar contained '\v\$\{\h\w*%(\[\d+%(-\d+)?\])?%(:\S*)?\}' contains=@tcshModifiers,tcshShellVar,tcshEnvVar
163syn match tcshArgv contained '\v\$\{%(\d+|\*)%(:\S*)?\}' contains=@tcshModifiers
Bram Moolenaar071d4272004-06-13 20:20:40 +0000164
Bram Moolenaara7241f52008-06-24 20:39:31 +0000165" Un-modifiable Substitutions. Order is important here.
166syn match tcshSubst contained '\v\$[?#$!_<]' nextgroup=tcshModifierError
167syn match tcshSubst contained '\v\$[%#?]%(\h\w*|\d+)' nextgroup=tcshModifierError contains=tcshShellVar,tcshEnvVar
168syn match tcshSubst contained '\v\$\{[%#?]%(\h\w*|\d+)%(:\S*)?\}' contains=tcshModifierError contains=tcshShellVar,tcshEnvVar
Bram Moolenaar071d4272004-06-13 20:20:40 +0000169
170" Variable Name Expansion Modifiers (order important)
171syn match tcshModifierError contained '\v:\S*'
172syn match tcshModifier contained '\v:[ag]?[htreuls&qx]' nextgroup=@tcshModifiers
173
174" ----- Operators / Specials -----
175" Standard redirects (except <<) [<, >, >>, >>&, >>!, >>&!]
Bram Moolenaara7241f52008-06-24 20:39:31 +0000176syn match tcshRedir contained '\v\<|\>\>?\&?!?'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000177
Bram Moolenaara7241f52008-06-24 20:39:31 +0000178" Meta-chars
179syn match tcshMeta contained '\v[]{}*?[]'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000180
Bram Moolenaara7241f52008-06-24 20:39:31 +0000181" Here documents (<<)
182syn region tcshHereDoc contained matchgroup=tcshShellVar start='\v\<\<\s*\z(\h\w*)' end='^\z1$' contains=@tcshVarList,tcshSpecial
183syn region tcshHereDoc contained matchgroup=tcshShellVar start="\v\<\<\s*'\z(\h\w*)'" start='\v\<\<\s*"\z(\h\w*)"$' start='\v\<\<\s*\\\z(\h\w*)$' end='^\z1$'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000184
185" Operators
Bram Moolenaara7241f52008-06-24 20:39:31 +0000186syn match tcshOperator contained '&&\|!\~\|!=\|<<\|<=\|==\|=\~\|>=\|>>\|\*\|\^\|\~\|||\|!\|%\|&\|+\|-\|/\|<\|>\||'
187"syn match tcshOperator contained '[(){}]'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000188
189" Numbers
Bram Moolenaara7241f52008-06-24 20:39:31 +0000190syn match tcshNumber contained '\v<-?\d+>'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000191
Bram Moolenaara7241f52008-06-24 20:39:31 +0000192" Arguments
193syn match tcshArguement contained '\v\s@<=-(\w|-)*'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000194
Bram Moolenaara7241f52008-06-24 20:39:31 +0000195" Special characters. \xxx, or backslashed characters.
196"syn match tcshSpecial contained '\v\\@<!\\(\d{3}|.)'
197syn match tcshSpecial contained '\v\\%([0-7]{3}|.)'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000198
Bram Moolenaara7241f52008-06-24 20:39:31 +0000199" ----- Synchronising -----
200if exists('tcsh_minlines')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100201 if tcsh_minlines == 'fromstart'
202 syn sync fromstart
203 else
204 exec 'syn sync minlines=' . tcsh_minlines
205 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000206else
Bram Moolenaara7241f52008-06-24 20:39:31 +0000207 syn sync minlines=100 " Some completions can be quite long
Bram Moolenaar071d4272004-06-13 20:20:40 +0000208endif
209
210" Define highlighting of syntax groups
Bram Moolenaara7241f52008-06-24 20:39:31 +0000211hi def link tcshError Error
212hi def link tcshBuiltin Statement
213hi def link tcshShellVar Preproc
Bram Moolenaar071d4272004-06-13 20:20:40 +0000214hi def link tcshEnvVar tcshShellVar
215hi def link tcshAliases tcshShellVar
Bram Moolenaara7241f52008-06-24 20:39:31 +0000216hi def link tcshAliCmd Identifier
217hi def link tcshCommands Identifier
218hi def link tcshIf tcshBuiltin
219hi def link tcshWhile tcshBuiltin
220hi def link tcshBindkeyFuncs Function
221hi def link tcshExprStart tcshBuiltin
Bram Moolenaar071d4272004-06-13 20:20:40 +0000222hi def link tcshExprVar tcshUsrVar
223hi def link tcshExprOp tcshOperator
224hi def link tcshExprEnd tcshOperator
Bram Moolenaara7241f52008-06-24 20:39:31 +0000225hi def link tcshComment Comment
226hi def link tcshCommentTi Preproc
Bram Moolenaara83c3e02006-03-17 23:10:44 +0000227hi def link tcshSharpBang tcshCommentTi
Bram Moolenaara7241f52008-06-24 20:39:31 +0000228hi def link tcshTodo Todo
229hi def link tcshSQuote Constant
Bram Moolenaar071d4272004-06-13 20:20:40 +0000230hi def link tcshDQuote tcshSQuote
Bram Moolenaara7241f52008-06-24 20:39:31 +0000231hi def link tcshBQuoteGrp Include
232hi def link tcshVarError Error
233hi def link tcshUsrVar Type
Bram Moolenaar071d4272004-06-13 20:20:40 +0000234hi def link tcshArgv tcshUsrVar
235hi def link tcshSubst tcshUsrVar
236hi def link tcshModifier tcshArguement
237hi def link tcshModifierError tcshVarError
238hi def link tcshMeta tcshSubst
239hi def link tcshRedir tcshOperator
240hi def link tcshHereDoc tcshSQuote
Bram Moolenaara7241f52008-06-24 20:39:31 +0000241hi def link tcshOperator Operator
242hi def link tcshNumber Number
243hi def link tcshArguement Special
244hi def link tcshSpecial SpecialChar
Bram Moolenaar071d4272004-06-13 20:20:40 +0000245
Bram Moolenaara7241f52008-06-24 20:39:31 +0000246let &cpo = s:oldcpo
247unlet s:oldcpo
248
249let b:current_syntax = 'tcsh'