blob: 94c4181c3af0fdfb3d0c091b98d458475609fa44 [file] [log] [blame]
Bram Moolenaara7241f52008-06-24 20:39:31 +00001" tcsh.vim: Vim syntax file for tcsh scripts
2" Maintainer: Gautam Iyer <gi1242@users.sourceforge.net>
3" Modified: Sat 16 Jun 2007 04:52:12 PM PDT
Bram Moolenaar071d4272004-06-13 20:20:40 +00004"
5" Description: We break up each statement into a "command" and an "end" part.
6" All groups are either a "command" or part of the "end" of a statement (ie
7" everything after the "command"). This is because blindly highlighting tcsh
8" statements as keywords caused way too many false positives. Eg:
9"
Bram Moolenaara83c3e02006-03-17 23:10:44 +000010" set history=200
Bram Moolenaar071d4272004-06-13 20:20:40 +000011"
12" causes history to come up as a keyword, which we want to avoid.
13
14" Quit when a syntax file was already loaded
Bram Moolenaara7241f52008-06-24 20:39:31 +000015if exists('b:current_syntax')
Bram Moolenaar071d4272004-06-13 20:20:40 +000016 finish
17endif
18
Bram Moolenaara7241f52008-06-24 20:39:31 +000019let s:oldcpo = &cpo
20set cpo&vim " Line continuation is used
21
22setlocal iskeyword+=-
23
Bram Moolenaar071d4272004-06-13 20:20:40 +000024syn case match
25
26" ----- Clusters -----
27syn cluster tcshModifiers contains=tcshModifier,tcshModifierError
28syn cluster tcshQuoteList contains=tcshDQuote,tcshSQuote,tcshBQuote
Bram Moolenaara7241f52008-06-24 20:39:31 +000029syn cluster tcshStatementEnds contains=@tcshQuoteList,tcshComment,@tcshVarList,tcshRedir,tcshMeta,tcshHereDoc,tcshSpecial,tcshArguement
30syn cluster tcshStatements contains=tcshBuiltin,tcshCommands,tcshIf,tcshWhile
Bram Moolenaar071d4272004-06-13 20:20:40 +000031syn cluster tcshVarList contains=tcshUsrVar,tcshArgv,tcshSubst
Bram Moolenaara7241f52008-06-24 20:39:31 +000032syn cluster tcshConditions contains=tcshCmdSubst,tcshParenExpr,tcshOperator,tcshNumber,@tcshVarList
33
34" ----- Errors -----
35" Define first, so can be easily overridden.
36syn match tcshError contained '\v\S.+'
Bram Moolenaar071d4272004-06-13 20:20:40 +000037
38" ----- Statements -----
39" Tcsh commands: Any filename / modifiable variable (must be first!)
40syn match tcshCommands '\v[a-zA-Z0-9\\./_$:-]+' contains=tcshSpecial,tcshUsrVar,tcshArgv,tcshVarError nextgroup=tcshStatementEnd
41
Bram Moolenaara7241f52008-06-24 20:39:31 +000042" Builtin commands except those treated specially. Currently (un)set(env),
43" (un)alias, if, while, else, bindkey
44syn 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 +000045
Bram Moolenaara7241f52008-06-24 20:39:31 +000046" StatementEnd is anything after a built-in / command till the lexical end of a
Bram Moolenaar071d4272004-06-13 20:20:40 +000047" statement (;, |, ||, |&, && or end of line)
Bram Moolenaara7241f52008-06-24 20:39:31 +000048syn region tcshStatementEnd transparent contained matchgroup=tcshBuiltin start='' end='\v\\@<!(;|\|[|&]?|\&\&|$)' contains=@tcshStatementEnds
Bram Moolenaar071d4272004-06-13 20:20:40 +000049
50" set expressions (Contains shell variables)
51syn 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 +000052syn keyword tcshBuiltin nextgroup=tcshSetEnd set unset
53syn region tcshSetEnd contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$\|;' contains=tcshShellVar,@tcshStatementEnds
Bram Moolenaar071d4272004-06-13 20:20:40 +000054
Bram Moolenaara7241f52008-06-24 20:39:31 +000055" setenv expressions (Contains environment variables)
Bram Moolenaar071d4272004-06-13 20:20:40 +000056syn 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 +000057syn keyword tcshBuiltin nextgroup=tcshEnvEnd setenv unsetenv
58syn region tcshEnvEnd contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$\|;' contains=tcshEnvVar,@tcshStatementEnds
Bram Moolenaar071d4272004-06-13 20:20:40 +000059
60" alias and unalias (contains special aliases)
Bram Moolenaar9964e462007-05-05 17:54:07 +000061syn keyword tcshAliases contained beepcmd cwdcmd jobcmd helpcommand periodic precmd postcmd shell
Bram Moolenaara7241f52008-06-24 20:39:31 +000062syn keyword tcshBuiltin nextgroup=tcshAliCmd skipwhite alias unalias
Bram Moolenaar9964e462007-05-05 17:54:07 +000063syn match tcshAliCmd contained nextgroup=tcshAliEnd skipwhite '\v[\w-]+' contains=tcshAliases
Bram Moolenaara7241f52008-06-24 20:39:31 +000064syn region tcshAliEnd contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$\|;' contains=@tcshStatementEnds
Bram Moolenaar071d4272004-06-13 20:20:40 +000065
Bram Moolenaara7241f52008-06-24 20:39:31 +000066" if statements
67syn keyword tcshIf nextgroup=tcshIfEnd skipwhite if
68syn region tcshIfEnd contained start='\S' skip='\\$' matchgroup=tcshBuiltin end='\v<then>|$' contains=@tcshConditions,tcshSpecial,@tcshStatementEnds
69syn region tcshIfEnd contained matchgroup=tcshBuiltin contains=@tcshConditions,tcshSpecial start='(' end='\v\)%(\s+then>)?' skipwhite nextgroup=@tcshStatementEnds
70syn 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 +000071
Bram Moolenaara7241f52008-06-24 20:39:31 +000072" else statements
73syn keyword tcshBuiltin nextgroup=tcshIf skipwhite else
Bram Moolenaar071d4272004-06-13 20:20:40 +000074
75" while statements (contains expressions / operators)
Bram Moolenaara7241f52008-06-24 20:39:31 +000076syn keyword tcshBuiltin nextgroup=@tcshConditions,tcshSpecial skipwhite while
77
78" Conditions (for if and while)
79syn region tcshParenExpr contained contains=@tcshConditions,tcshSpecial matchgroup=tcshBuiltin start='(' end=')'
80syn region tcshCmdSubst contained contains=tcshCommands matchgroup=tcshBuiltin start='\v\{\s+' end='\v\s+\}' keepend
81
82" Bindkey. Internal editor functions
83syn keyword tcshBindkeyFuncs contained backward-char backward-delete-char
84 \ backward-delete-word backward-kill-line backward-word
85 \ beginning-of-line capitalize-word change-case
86 \ change-till-end-of-line clear-screen complete-word
87 \ complete-word-fwd complete-word-back complete-word-raw
88 \ copy-prev-word copy-region-as-kill dabbrev-expand delete-char
89 \ delete-char-or-eof delete-char-or-list
90 \ delete-char-or-list-or-eof delete-word digit digit-argument
91 \ down-history downcase-word end-of-file end-of-line
92 \ exchange-point-and-mark expand-glob expand-history expand-line
93 \ expand-variables forward-char forward-word
94 \ gosmacs-transpose-chars history-search-backward
95 \ history-search-forward insert-last-word i-search-fwd
96 \ i-search-back keyboard-quit kill-line kill-region
97 \ kill-whole-line list-choices list-choices-raw list-glob
98 \ list-or-eof load-average magic-space newline normalize-path
99 \ normalize-command overwrite-mode prefix-meta quoted-insert
100 \ redisplay run-fg-editor run-help self-insert-command
101 \ sequence-lead-in set-mark-command spell-word spell-line
102 \ stuff-char toggle-literal-history transpose-chars
103 \ transpose-gosling tty-dsusp tty-flush-output tty-sigintr
104 \ tty-sigquit tty-sigtsusp tty-start-output tty-stop-output
105 \ undefined-key universal-argument up-history upcase-word
106 \ vi-beginning-of-next-word vi-add vi-add-at-eol vi-chg-case
107 \ vi-chg-meta vi-chg-to-eol vi-cmd-mode vi-cmd-mode-complete
108 \ vi-delprev vi-delmeta vi-endword vi-eword vi-char-back
109 \ vi-char-fwd vi-charto-back vi-charto-fwd vi-insert
110 \ vi-insert-at-bol vi-repeat-char-fwd vi-repeat-char-back
111 \ vi-repeat-search-fwd vi-repeat-search-back vi-replace-char
112 \ vi-replace-mode vi-search-back vi-search-fwd vi-substitute-char
113 \ vi-substitute-line vi-word-back vi-word-fwd vi-undo vi-zero
114 \ which-command yank yank-pop e_copy_to_clipboard
115 \ e_paste_from_clipboard e_dosify_next e_dosify_prev e_page_up
116 \ e_page_down
117syn keyword tcshBuiltin nextgroup=tcshBindkeyEnd bindkey
118syn region tcshBindkeyEnd contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$' contains=@tcshQuoteList,tcshComment,@tcshVarList,tcshMeta,tcshSpecial,tcshArguement,tcshBindkeyFuncs
Bram Moolenaar071d4272004-06-13 20:20:40 +0000119
120" Expressions start with @.
Bram Moolenaara7241f52008-06-24 20:39:31 +0000121syn match tcshExprStart '\v\@\s+' nextgroup=tcshExprVar
122syn match tcshExprVar contained '\v\h\w*%(\[\d+\])?' contains=tcshShellVar,tcshEnvVar nextgroup=tcshExprOp
123syn match tcshExprOp contained '++\|--'
124syn match tcshExprOp contained '\v\s*\=' nextgroup=tcshExprEnd
125syn match tcshExprEnd contained '\v.*$'hs=e+1 contains=@tcshConditions
126syn match tcshExprEnd contained '\v.{-};'hs=e contains=@tcshConditions
Bram Moolenaar071d4272004-06-13 20:20:40 +0000127
128" ----- Comments: -----
Bram Moolenaar9964e462007-05-05 17:54:07 +0000129syn match tcshComment '#\s.*' contains=tcshTodo,tcshCommentTi,@Spell
130syn match tcshComment '\v#($|\S.*)' contains=tcshTodo,tcshCommentTi
131syn match tcshSharpBang '^#! .*$'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000132syn match tcshCommentTi contained '\v#\s*\u\w*(\s+\u\w*)*:'hs=s+1 contains=tcshTodo
Bram Moolenaar071d4272004-06-13 20:20:40 +0000133syn match tcshTodo contained '\v\c<todo>'
134
135" ----- Strings -----
136" Tcsh does not allow \" in strings unless the "backslash_quote" shell
137" variable is set. Set the vim variable "tcsh_backslash_quote" to 0 if you
138" want VIM to assume that no backslash quote constructs exist.
139
140" Backquotes are treated as commands, and are not contained in anything
Bram Moolenaara7241f52008-06-24 20:39:31 +0000141if(exists('tcsh_backslash_quote') && tcsh_backslash_quote == 0)
142 syn region tcshSQuote keepend contained start="\v\\@<!'" end="'"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000143 syn region tcshDQuote keepend contained start='\v\\@<!"' end='"' contains=@tcshVarList,tcshSpecial,@Spell
144 syn region tcshBQuote keepend start='\v\\@<!`' end='`' contains=@tcshStatements
145else
Bram Moolenaara7241f52008-06-24 20:39:31 +0000146 syn region tcshSQuote contained start="\v\\@<!'" skip="\v\\\\|\\'" end="'"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000147 syn region tcshDQuote contained start='\v\\@<!"' end='"' contains=@tcshVarList,tcshSpecial,@Spell
148 syn region tcshBQuote keepend matchgroup=tcshBQuoteGrp start='\v\\@<!`' skip='\v\\\\|\\`' end='`' contains=@tcshStatements
149endif
150
151" ----- Variables -----
152" Variable Errors. Must come first! \$ constructs will be flagged by
153" tcshSpecial, so we don't consider them here.
154syn match tcshVarError '\v\$\S*' contained
155
156" Modifiable Variables without {}.
Bram Moolenaara7241f52008-06-24 20:39:31 +0000157syn match tcshUsrVar contained '\v\$\h\w*%(\[\d+%(-\d+)?\])?' nextgroup=@tcshModifiers contains=tcshShellVar,tcshEnvVar
158syn match tcshArgv contained '\v\$%(\d+|\*)' nextgroup=@tcshModifiers
Bram Moolenaar071d4272004-06-13 20:20:40 +0000159
160" Modifiable Variables with {}.
Bram Moolenaara7241f52008-06-24 20:39:31 +0000161syn match tcshUsrVar contained '\v\$\{\h\w*%(\[\d+%(-\d+)?\])?%(:\S*)?\}' contains=@tcshModifiers,tcshShellVar,tcshEnvVar
162syn match tcshArgv contained '\v\$\{%(\d+|\*)%(:\S*)?\}' contains=@tcshModifiers
Bram Moolenaar071d4272004-06-13 20:20:40 +0000163
Bram Moolenaara7241f52008-06-24 20:39:31 +0000164" Un-modifiable Substitutions. Order is important here.
165syn match tcshSubst contained '\v\$[?#$!_<]' nextgroup=tcshModifierError
166syn match tcshSubst contained '\v\$[%#?]%(\h\w*|\d+)' nextgroup=tcshModifierError contains=tcshShellVar,tcshEnvVar
167syn match tcshSubst contained '\v\$\{[%#?]%(\h\w*|\d+)%(:\S*)?\}' contains=tcshModifierError contains=tcshShellVar,tcshEnvVar
Bram Moolenaar071d4272004-06-13 20:20:40 +0000168
169" Variable Name Expansion Modifiers (order important)
170syn match tcshModifierError contained '\v:\S*'
171syn match tcshModifier contained '\v:[ag]?[htreuls&qx]' nextgroup=@tcshModifiers
172
173" ----- Operators / Specials -----
174" Standard redirects (except <<) [<, >, >>, >>&, >>!, >>&!]
Bram Moolenaara7241f52008-06-24 20:39:31 +0000175syn match tcshRedir contained '\v\<|\>\>?\&?!?'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000176
Bram Moolenaara7241f52008-06-24 20:39:31 +0000177" Meta-chars
178syn match tcshMeta contained '\v[]{}*?[]'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000179
Bram Moolenaara7241f52008-06-24 20:39:31 +0000180" Here documents (<<)
181syn region tcshHereDoc contained matchgroup=tcshShellVar start='\v\<\<\s*\z(\h\w*)' end='^\z1$' contains=@tcshVarList,tcshSpecial
182syn 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 +0000183
184" Operators
Bram Moolenaara7241f52008-06-24 20:39:31 +0000185syn match tcshOperator contained '&&\|!\~\|!=\|<<\|<=\|==\|=\~\|>=\|>>\|\*\|\^\|\~\|||\|!\|%\|&\|+\|-\|/\|<\|>\||'
186"syn match tcshOperator contained '[(){}]'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000187
188" Numbers
Bram Moolenaara7241f52008-06-24 20:39:31 +0000189syn match tcshNumber contained '\v<-?\d+>'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000190
Bram Moolenaara7241f52008-06-24 20:39:31 +0000191" Arguments
192syn match tcshArguement contained '\v\s@<=-(\w|-)*'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000193
Bram Moolenaara7241f52008-06-24 20:39:31 +0000194" Special characters. \xxx, or backslashed characters.
195"syn match tcshSpecial contained '\v\\@<!\\(\d{3}|.)'
196syn match tcshSpecial contained '\v\\%([0-7]{3}|.)'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000197
Bram Moolenaara7241f52008-06-24 20:39:31 +0000198" ----- Synchronising -----
199if exists('tcsh_minlines')
200 exec 'syn sync minlines=' . tcsh_minlines
Bram Moolenaar071d4272004-06-13 20:20:40 +0000201else
Bram Moolenaara7241f52008-06-24 20:39:31 +0000202 syn sync minlines=100 " Some completions can be quite long
Bram Moolenaar071d4272004-06-13 20:20:40 +0000203endif
204
205" Define highlighting of syntax groups
Bram Moolenaara7241f52008-06-24 20:39:31 +0000206hi def link tcshError Error
207hi def link tcshBuiltin Statement
208hi def link tcshShellVar Preproc
Bram Moolenaar071d4272004-06-13 20:20:40 +0000209hi def link tcshEnvVar tcshShellVar
210hi def link tcshAliases tcshShellVar
Bram Moolenaara7241f52008-06-24 20:39:31 +0000211hi def link tcshAliCmd Identifier
212hi def link tcshCommands Identifier
213hi def link tcshIf tcshBuiltin
214hi def link tcshWhile tcshBuiltin
215hi def link tcshBindkeyFuncs Function
216hi def link tcshExprStart tcshBuiltin
Bram Moolenaar071d4272004-06-13 20:20:40 +0000217hi def link tcshExprVar tcshUsrVar
218hi def link tcshExprOp tcshOperator
219hi def link tcshExprEnd tcshOperator
Bram Moolenaara7241f52008-06-24 20:39:31 +0000220hi def link tcshComment Comment
221hi def link tcshCommentTi Preproc
Bram Moolenaara83c3e02006-03-17 23:10:44 +0000222hi def link tcshSharpBang tcshCommentTi
Bram Moolenaara7241f52008-06-24 20:39:31 +0000223hi def link tcshTodo Todo
224hi def link tcshSQuote Constant
Bram Moolenaar071d4272004-06-13 20:20:40 +0000225hi def link tcshDQuote tcshSQuote
Bram Moolenaara7241f52008-06-24 20:39:31 +0000226hi def link tcshBQuoteGrp Include
227hi def link tcshVarError Error
228hi def link tcshUsrVar Type
Bram Moolenaar071d4272004-06-13 20:20:40 +0000229hi def link tcshArgv tcshUsrVar
230hi def link tcshSubst tcshUsrVar
231hi def link tcshModifier tcshArguement
232hi def link tcshModifierError tcshVarError
233hi def link tcshMeta tcshSubst
234hi def link tcshRedir tcshOperator
235hi def link tcshHereDoc tcshSQuote
Bram Moolenaara7241f52008-06-24 20:39:31 +0000236hi def link tcshOperator Operator
237hi def link tcshNumber Number
238hi def link tcshArguement Special
239hi def link tcshSpecial SpecialChar
Bram Moolenaar071d4272004-06-13 20:20:40 +0000240
Bram Moolenaara7241f52008-06-24 20:39:31 +0000241let &cpo = s:oldcpo
242unlet s:oldcpo
243
244let b:current_syntax = 'tcsh'