blob: 6837125129bc754b694953b0b0102e0cf73d8d48 [file] [log] [blame]
Bram Moolenaar22863042021-10-16 15:23:36 +01001" Vim syntax file
2" Language: tcsh scripts
3" Maintainer: Doug Kearns <dougkearns@gmail.com>
4" Previous Maintainer: Gautam Iyer <gi1242+vim@NoSpam.com> where NoSpam=gmail (Original Author)
5" Last Change: 2021 Oct 15
6
Bram Moolenaar071d4272004-06-13 20:20:40 +00007" Description: We break up each statement into a "command" and an "end" part.
8" All groups are either a "command" or part of the "end" of a statement (ie
9" everything after the "command"). This is because blindly highlighting tcsh
10" statements as keywords caused way too many false positives. Eg:
11"
Bram Moolenaara83c3e02006-03-17 23:10:44 +000012" set history=200
Bram Moolenaar071d4272004-06-13 20:20:40 +000013"
14" causes history to come up as a keyword, which we want to avoid.
15
16" Quit when a syntax file was already loaded
Bram Moolenaara7241f52008-06-24 20:39:31 +000017if exists('b:current_syntax')
Bram Moolenaar071d4272004-06-13 20:20:40 +000018 finish
19endif
20
Bram Moolenaara7241f52008-06-24 20:39:31 +000021let s:oldcpo = &cpo
22set cpo&vim " Line continuation is used
23
Bram Moolenaar22863042021-10-16 15:23:36 +010024syn iskeyword @,48-57,_,192-255,-
Bram Moolenaara7241f52008-06-24 20:39:31 +000025
Bram Moolenaar071d4272004-06-13 20:20:40 +000026syn case match
27
Bram Moolenaar22863042021-10-16 15:23:36 +010028" ----- Clusters ----- {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000029syn cluster tcshModifiers contains=tcshModifier,tcshModifierError
30syn cluster tcshQuoteList contains=tcshDQuote,tcshSQuote,tcshBQuote
Bram Moolenaar22863042021-10-16 15:23:36 +010031syn cluster tcshStatementEnds contains=@tcshQuoteList,tcshComment,@tcshVarList,tcshRedir,tcshMeta,tcshHereDoc,tcshSpecial,tcshArgument
Bram Moolenaara7241f52008-06-24 20:39:31 +000032syn cluster tcshStatements contains=tcshBuiltin,tcshCommands,tcshIf,tcshWhile
Bram Moolenaar071d4272004-06-13 20:20:40 +000033syn cluster tcshVarList contains=tcshUsrVar,tcshArgv,tcshSubst
Bram Moolenaara7241f52008-06-24 20:39:31 +000034syn cluster tcshConditions contains=tcshCmdSubst,tcshParenExpr,tcshOperator,tcshNumber,@tcshVarList
35
Bram Moolenaar22863042021-10-16 15:23:36 +010036" ----- Errors ----- {{{1
Bram Moolenaara7241f52008-06-24 20:39:31 +000037" Define first, so can be easily overridden.
38syn match tcshError contained '\v\S.+'
Bram Moolenaar071d4272004-06-13 20:20:40 +000039
Bram Moolenaar22863042021-10-16 15:23:36 +010040" ----- Statements ----- {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000041" Tcsh commands: Any filename / modifiable variable (must be first!)
42syn match tcshCommands '\v[a-zA-Z0-9\\./_$:-]+' contains=tcshSpecial,tcshUsrVar,tcshArgv,tcshVarError nextgroup=tcshStatementEnd
43
Bram Moolenaara7241f52008-06-24 20:39:31 +000044" Builtin commands except those treated specially. Currently (un)set(env),
45" (un)alias, if, while, else, bindkey
Bram Moolenaar22863042021-10-16 15:23:36 +010046syn 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 termname time umask uncomplete unhash universe unlimit ver wait warp watchlog where which
Bram Moolenaar071d4272004-06-13 20:20:40 +000047
Bram Moolenaara7241f52008-06-24 20:39:31 +000048" StatementEnd is anything after a built-in / command till the lexical end of a
Bram Moolenaar071d4272004-06-13 20:20:40 +000049" statement (;, |, ||, |&, && or end of line)
Bram Moolenaara7241f52008-06-24 20:39:31 +000050syn region tcshStatementEnd transparent contained matchgroup=tcshBuiltin start='' end='\v\\@<!(;|\|[|&]?|\&\&|$)' contains=@tcshStatementEnds
Bram Moolenaar071d4272004-06-13 20:20:40 +000051
52" set expressions (Contains shell variables)
Bram Moolenaar22863042021-10-16 15:23:36 +010053syn keyword tcshShellVar contained addsuffix afsuser ampm anyerror argv autocorrect autoexpand autolist autologout autorehash backslash_quote catalog cdpath cdtohome color colorcat command compat_expr complete continue continue_args correct csubstnonl cwd dextract dirsfile dirstack dspmbyte dunique echo echo_style edit editors ellipsis euid euser fignore filec gid globdot globstar group highlight 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 padhour parseoctal 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 vimode visiblebell watch who wordchars
Bram Moolenaara7241f52008-06-24 20:39:31 +000054syn keyword tcshBuiltin nextgroup=tcshSetEnd set unset
55syn region tcshSetEnd contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$\|;' contains=tcshShellVar,@tcshStatementEnds
Bram Moolenaar071d4272004-06-13 20:20:40 +000056
Bram Moolenaara7241f52008-06-24 20:39:31 +000057" setenv expressions (Contains environment variables)
Bram Moolenaar071d4272004-06-13 20:20:40 +000058syn 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 +000059syn keyword tcshBuiltin nextgroup=tcshEnvEnd setenv unsetenv
60syn region tcshEnvEnd contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$\|;' contains=tcshEnvVar,@tcshStatementEnds
Bram Moolenaar071d4272004-06-13 20:20:40 +000061
62" alias and unalias (contains special aliases)
Bram Moolenaar9964e462007-05-05 17:54:07 +000063syn keyword tcshAliases contained beepcmd cwdcmd jobcmd helpcommand periodic precmd postcmd shell
Bram Moolenaara7241f52008-06-24 20:39:31 +000064syn keyword tcshBuiltin nextgroup=tcshAliCmd skipwhite alias unalias
Bram Moolenaar5c736222010-01-06 20:54:52 +010065syn match tcshAliCmd contained nextgroup=tcshAliEnd skipwhite '\v(\w|-)+' contains=tcshAliases
Bram Moolenaara7241f52008-06-24 20:39:31 +000066syn region tcshAliEnd contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$\|;' contains=@tcshStatementEnds
Bram Moolenaar071d4272004-06-13 20:20:40 +000067
Bram Moolenaara7241f52008-06-24 20:39:31 +000068" if statements
69syn keyword tcshIf nextgroup=tcshIfEnd skipwhite if
70syn region tcshIfEnd contained start='\S' skip='\\$' matchgroup=tcshBuiltin end='\v<then>|$' contains=@tcshConditions,tcshSpecial,@tcshStatementEnds
71syn region tcshIfEnd contained matchgroup=tcshBuiltin contains=@tcshConditions,tcshSpecial start='(' end='\v\)%(\s+then>)?' skipwhite nextgroup=@tcshStatementEnds
72syn 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 +000073
Bram Moolenaara7241f52008-06-24 20:39:31 +000074" else statements
75syn keyword tcshBuiltin nextgroup=tcshIf skipwhite else
Bram Moolenaar071d4272004-06-13 20:20:40 +000076
77" while statements (contains expressions / operators)
Bram Moolenaara7241f52008-06-24 20:39:31 +000078syn keyword tcshBuiltin nextgroup=@tcshConditions,tcshSpecial skipwhite while
79
80" Conditions (for if and while)
81syn region tcshParenExpr contained contains=@tcshConditions,tcshSpecial matchgroup=tcshBuiltin start='(' end=')'
82syn region tcshCmdSubst contained contains=tcshCommands matchgroup=tcshBuiltin start='\v\{\s+' end='\v\s+\}' keepend
83
84" Bindkey. Internal editor functions
85syn keyword tcshBindkeyFuncs contained backward-char backward-delete-char
86 \ backward-delete-word backward-kill-line backward-word
87 \ beginning-of-line capitalize-word change-case
88 \ change-till-end-of-line clear-screen complete-word
89 \ complete-word-fwd complete-word-back complete-word-raw
90 \ copy-prev-word copy-region-as-kill dabbrev-expand delete-char
91 \ delete-char-or-eof delete-char-or-list
92 \ delete-char-or-list-or-eof delete-word digit digit-argument
93 \ down-history downcase-word end-of-file end-of-line
94 \ exchange-point-and-mark expand-glob expand-history expand-line
95 \ expand-variables forward-char forward-word
96 \ gosmacs-transpose-chars history-search-backward
97 \ history-search-forward insert-last-word i-search-fwd
98 \ i-search-back keyboard-quit kill-line kill-region
99 \ kill-whole-line list-choices list-choices-raw list-glob
Bram Moolenaar22863042021-10-16 15:23:36 +0100100 \ list-or-eof load-average magic-space newline newline-and-hold
101 \ newline-and-down-history normalize-path normalize-command
102 \ overwrite-mode prefix-meta quoted-insert redisplay
103 \ run-fg-editor run-help self-insert-command sequence-lead-in
104 \ set-mark-command spell-word spell-line stuff-char
105 \ toggle-literal-history transpose-chars transpose-gosling
106 \ tty-dsusp tty-flush-output tty-sigintr tty-sigquit tty-sigtsusp
107 \ tty-start-output tty-stop-output undefined-key
108 \ universal-argument up-history upcase-word
Bram Moolenaara7241f52008-06-24 20:39:31 +0000109 \ vi-beginning-of-next-word vi-add vi-add-at-eol vi-chg-case
110 \ vi-chg-meta vi-chg-to-eol vi-cmd-mode vi-cmd-mode-complete
111 \ vi-delprev vi-delmeta vi-endword vi-eword vi-char-back
112 \ vi-char-fwd vi-charto-back vi-charto-fwd vi-insert
113 \ vi-insert-at-bol vi-repeat-char-fwd vi-repeat-char-back
114 \ vi-repeat-search-fwd vi-repeat-search-back vi-replace-char
115 \ vi-replace-mode vi-search-back vi-search-fwd vi-substitute-char
116 \ vi-substitute-line vi-word-back vi-word-fwd vi-undo vi-zero
117 \ which-command yank yank-pop e_copy_to_clipboard
118 \ e_paste_from_clipboard e_dosify_next e_dosify_prev e_page_up
119 \ e_page_down
120syn keyword tcshBuiltin nextgroup=tcshBindkeyEnd bindkey
Bram Moolenaar22863042021-10-16 15:23:36 +0100121syn region tcshBindkeyEnd contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$' contains=@tcshQuoteList,tcshComment,@tcshVarList,tcshMeta,tcshSpecial,tcshArgument,tcshBindkeyFuncs
Bram Moolenaar071d4272004-06-13 20:20:40 +0000122
123" Expressions start with @.
Bram Moolenaara7241f52008-06-24 20:39:31 +0000124syn match tcshExprStart '\v\@\s+' nextgroup=tcshExprVar
125syn match tcshExprVar contained '\v\h\w*%(\[\d+\])?' contains=tcshShellVar,tcshEnvVar nextgroup=tcshExprOp
126syn match tcshExprOp contained '++\|--'
127syn match tcshExprOp contained '\v\s*\=' nextgroup=tcshExprEnd
128syn match tcshExprEnd contained '\v.*$'hs=e+1 contains=@tcshConditions
129syn match tcshExprEnd contained '\v.{-};'hs=e contains=@tcshConditions
Bram Moolenaar071d4272004-06-13 20:20:40 +0000130
Bram Moolenaar22863042021-10-16 15:23:36 +0100131" ----- Comments: ----- {{{1
Bram Moolenaar9964e462007-05-05 17:54:07 +0000132syn match tcshComment '#\s.*' contains=tcshTodo,tcshCommentTi,@Spell
133syn match tcshComment '\v#($|\S.*)' contains=tcshTodo,tcshCommentTi
134syn match tcshSharpBang '^#! .*$'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000135syn match tcshCommentTi contained '\v#\s*\u\w*(\s+\u\w*)*:'hs=s+1 contains=tcshTodo
Bram Moolenaar071d4272004-06-13 20:20:40 +0000136syn match tcshTodo contained '\v\c<todo>'
137
Bram Moolenaar22863042021-10-16 15:23:36 +0100138" ----- Strings ----- {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000139" Tcsh does not allow \" in strings unless the "backslash_quote" shell
140" variable is set. Set the vim variable "tcsh_backslash_quote" to 0 if you
141" want VIM to assume that no backslash quote constructs exist.
142
143" Backquotes are treated as commands, and are not contained in anything
Bram Moolenaar22863042021-10-16 15:23:36 +0100144if exists('tcsh_backslash_quote') && tcsh_backslash_quote == 0
Bram Moolenaara7241f52008-06-24 20:39:31 +0000145 syn region tcshSQuote keepend contained start="\v\\@<!'" end="'"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000146 syn region tcshDQuote keepend contained start='\v\\@<!"' end='"' contains=@tcshVarList,tcshSpecial,@Spell
147 syn region tcshBQuote keepend start='\v\\@<!`' end='`' contains=@tcshStatements
148else
Bram Moolenaara7241f52008-06-24 20:39:31 +0000149 syn region tcshSQuote contained start="\v\\@<!'" skip="\v\\\\|\\'" end="'"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000150 syn region tcshDQuote contained start='\v\\@<!"' end='"' contains=@tcshVarList,tcshSpecial,@Spell
151 syn region tcshBQuote keepend matchgroup=tcshBQuoteGrp start='\v\\@<!`' skip='\v\\\\|\\`' end='`' contains=@tcshStatements
152endif
153
Bram Moolenaar22863042021-10-16 15:23:36 +0100154" ----- Variables ----- {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000155" Variable Errors. Must come first! \$ constructs will be flagged by
156" tcshSpecial, so we don't consider them here.
157syn match tcshVarError '\v\$\S*' contained
158
159" Modifiable Variables without {}.
Bram Moolenaara7241f52008-06-24 20:39:31 +0000160syn match tcshUsrVar contained '\v\$\h\w*%(\[\d+%(-\d+)?\])?' nextgroup=@tcshModifiers contains=tcshShellVar,tcshEnvVar
161syn match tcshArgv contained '\v\$%(\d+|\*)' nextgroup=@tcshModifiers
Bram Moolenaar071d4272004-06-13 20:20:40 +0000162
163" Modifiable Variables with {}.
Bram Moolenaara7241f52008-06-24 20:39:31 +0000164syn match tcshUsrVar contained '\v\$\{\h\w*%(\[\d+%(-\d+)?\])?%(:\S*)?\}' contains=@tcshModifiers,tcshShellVar,tcshEnvVar
165syn match tcshArgv contained '\v\$\{%(\d+|\*)%(:\S*)?\}' contains=@tcshModifiers
Bram Moolenaar071d4272004-06-13 20:20:40 +0000166
Bram Moolenaara7241f52008-06-24 20:39:31 +0000167" Un-modifiable Substitutions. Order is important here.
168syn match tcshSubst contained '\v\$[?#$!_<]' nextgroup=tcshModifierError
169syn match tcshSubst contained '\v\$[%#?]%(\h\w*|\d+)' nextgroup=tcshModifierError contains=tcshShellVar,tcshEnvVar
170syn match tcshSubst contained '\v\$\{[%#?]%(\h\w*|\d+)%(:\S*)?\}' contains=tcshModifierError contains=tcshShellVar,tcshEnvVar
Bram Moolenaar071d4272004-06-13 20:20:40 +0000171
172" Variable Name Expansion Modifiers (order important)
173syn match tcshModifierError contained '\v:\S*'
174syn match tcshModifier contained '\v:[ag]?[htreuls&qx]' nextgroup=@tcshModifiers
175
Bram Moolenaar22863042021-10-16 15:23:36 +0100176" ----- Operators / Specials ----- {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000177" Standard redirects (except <<) [<, >, >>, >>&, >>!, >>&!]
Bram Moolenaara7241f52008-06-24 20:39:31 +0000178syn match tcshRedir contained '\v\<|\>\>?\&?!?'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000179
Bram Moolenaara7241f52008-06-24 20:39:31 +0000180" Meta-chars
181syn match tcshMeta contained '\v[]{}*?[]'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000182
Bram Moolenaara7241f52008-06-24 20:39:31 +0000183" Here documents (<<)
184syn region tcshHereDoc contained matchgroup=tcshShellVar start='\v\<\<\s*\z(\h\w*)' end='^\z1$' contains=@tcshVarList,tcshSpecial
185syn 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 +0000186
187" Operators
Bram Moolenaara7241f52008-06-24 20:39:31 +0000188syn match tcshOperator contained '&&\|!\~\|!=\|<<\|<=\|==\|=\~\|>=\|>>\|\*\|\^\|\~\|||\|!\|%\|&\|+\|-\|/\|<\|>\||'
189"syn match tcshOperator contained '[(){}]'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000190
191" Numbers
Bram Moolenaara7241f52008-06-24 20:39:31 +0000192syn match tcshNumber contained '\v<-?\d+>'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000193
Bram Moolenaara7241f52008-06-24 20:39:31 +0000194" Arguments
Bram Moolenaar22863042021-10-16 15:23:36 +0100195syn match tcshArgument contained '\v\s@<=-(\w|-)*'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000196
Bram Moolenaara7241f52008-06-24 20:39:31 +0000197" Special characters. \xxx, or backslashed characters.
198"syn match tcshSpecial contained '\v\\@<!\\(\d{3}|.)'
199syn match tcshSpecial contained '\v\\%([0-7]{3}|.)'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000200
Bram Moolenaar22863042021-10-16 15:23:36 +0100201" ----- Synchronising ----- {{{1
Bram Moolenaara7241f52008-06-24 20:39:31 +0000202if exists('tcsh_minlines')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100203 if tcsh_minlines == 'fromstart'
204 syn sync fromstart
205 else
206 exec 'syn sync minlines=' . tcsh_minlines
207 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000208else
Bram Moolenaara7241f52008-06-24 20:39:31 +0000209 syn sync minlines=100 " Some completions can be quite long
Bram Moolenaar071d4272004-06-13 20:20:40 +0000210endif
211
Bram Moolenaar22863042021-10-16 15:23:36 +0100212" ----- Highlighting ----- {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000213" Define highlighting of syntax groups
Bram Moolenaara7241f52008-06-24 20:39:31 +0000214hi def link tcshError Error
215hi def link tcshBuiltin Statement
216hi def link tcshShellVar Preproc
Bram Moolenaar071d4272004-06-13 20:20:40 +0000217hi def link tcshEnvVar tcshShellVar
218hi def link tcshAliases tcshShellVar
Bram Moolenaara7241f52008-06-24 20:39:31 +0000219hi def link tcshAliCmd Identifier
220hi def link tcshCommands Identifier
221hi def link tcshIf tcshBuiltin
222hi def link tcshWhile tcshBuiltin
223hi def link tcshBindkeyFuncs Function
224hi def link tcshExprStart tcshBuiltin
Bram Moolenaar071d4272004-06-13 20:20:40 +0000225hi def link tcshExprVar tcshUsrVar
226hi def link tcshExprOp tcshOperator
227hi def link tcshExprEnd tcshOperator
Bram Moolenaara7241f52008-06-24 20:39:31 +0000228hi def link tcshComment Comment
229hi def link tcshCommentTi Preproc
Bram Moolenaara83c3e02006-03-17 23:10:44 +0000230hi def link tcshSharpBang tcshCommentTi
Bram Moolenaara7241f52008-06-24 20:39:31 +0000231hi def link tcshTodo Todo
232hi def link tcshSQuote Constant
Bram Moolenaar071d4272004-06-13 20:20:40 +0000233hi def link tcshDQuote tcshSQuote
Bram Moolenaara7241f52008-06-24 20:39:31 +0000234hi def link tcshBQuoteGrp Include
235hi def link tcshVarError Error
236hi def link tcshUsrVar Type
Bram Moolenaar071d4272004-06-13 20:20:40 +0000237hi def link tcshArgv tcshUsrVar
238hi def link tcshSubst tcshUsrVar
Bram Moolenaar22863042021-10-16 15:23:36 +0100239hi def link tcshModifier tcshArgument
Bram Moolenaar071d4272004-06-13 20:20:40 +0000240hi def link tcshModifierError tcshVarError
241hi def link tcshMeta tcshSubst
242hi def link tcshRedir tcshOperator
243hi def link tcshHereDoc tcshSQuote
Bram Moolenaara7241f52008-06-24 20:39:31 +0000244hi def link tcshOperator Operator
245hi def link tcshNumber Number
Bram Moolenaar22863042021-10-16 15:23:36 +0100246hi def link tcshArgument Special
Bram Moolenaara7241f52008-06-24 20:39:31 +0000247hi def link tcshSpecial SpecialChar
Bram Moolenaar22863042021-10-16 15:23:36 +0100248" }}}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000249
Bram Moolenaara7241f52008-06-24 20:39:31 +0000250let &cpo = s:oldcpo
251unlet s:oldcpo
252
253let b:current_syntax = 'tcsh'
Bram Moolenaar22863042021-10-16 15:23:36 +0100254
255" vim: nowrap sw=2 sts=2 ts=8 noet fdm=marker: