tcsh.vim 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. " 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. " 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. "
  11. " set history=200
  12. "
  13. " causes history to come up as a keyword, which we want to avoid.
  14. " Quit when a syntax file was already loaded
  15. if exists('b:current_syntax')
  16. finish
  17. endif
  18. let s:oldcpo = &cpo
  19. set cpo&vim " Line continuation is used
  20. syn iskeyword @,48-57,_,192-255,-
  21. syn case match
  22. " ----- Clusters ----- {{{1
  23. syn cluster tcshModifiers contains=tcshModifier,tcshModifierError
  24. syn cluster tcshQuoteList contains=tcshDQuote,tcshSQuote,tcshBQuote
  25. syn cluster tcshStatementEnds contains=@tcshQuoteList,tcshComment,@tcshVarList,tcshRedir,tcshMeta,tcshHereDoc,tcshSpecial,tcshArgument
  26. syn cluster tcshStatements contains=tcshBuiltin,tcshCommands,tcshIf,tcshWhile
  27. syn cluster tcshVarList contains=tcshUsrVar,tcshArgv,tcshSubst
  28. syn cluster tcshConditions contains=tcshCmdSubst,tcshParenExpr,tcshOperator,tcshNumber,@tcshVarList
  29. " ----- Errors ----- {{{1
  30. " Define first, so can be easily overridden.
  31. syn match tcshError contained '\v\S.+'
  32. " ----- Statements ----- {{{1
  33. " Tcsh commands: Any filename / modifiable variable (must be first!)
  34. syn match tcshCommands '\v[a-zA-Z0-9\\./_$:-]+' contains=tcshSpecial,tcshUsrVar,tcshArgv,tcshVarError nextgroup=tcshStatementEnd
  35. " Builtin commands except those treated specially. Currently (un)set(env),
  36. " (un)alias, if, while, else, bindkey
  37. syn 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
  38. " StatementEnd is anything after a built-in / command till the lexical end of a
  39. " statement (;, |, ||, |&, && or end of line)
  40. syn region tcshStatementEnd transparent contained matchgroup=tcshBuiltin start='' end='\v\\@<!(;|\|[|&]?|\&\&|$)' contains=@tcshStatementEnds
  41. " set expressions (Contains shell variables)
  42. syn 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
  43. syn keyword tcshBuiltin nextgroup=tcshSetEnd set unset
  44. syn region tcshSetEnd contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$\|;' contains=tcshShellVar,@tcshStatementEnds
  45. " setenv expressions (Contains environment variables)
  46. syn 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
  47. syn keyword tcshBuiltin nextgroup=tcshEnvEnd setenv unsetenv
  48. syn region tcshEnvEnd contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$\|;' contains=tcshEnvVar,@tcshStatementEnds
  49. " alias and unalias (contains special aliases)
  50. syn keyword tcshAliases contained beepcmd cwdcmd jobcmd helpcommand periodic precmd postcmd shell
  51. syn keyword tcshBuiltin nextgroup=tcshAliCmd skipwhite alias unalias
  52. syn match tcshAliCmd contained nextgroup=tcshAliEnd skipwhite '\v(\w|-)+' contains=tcshAliases
  53. syn region tcshAliEnd contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$\|;' contains=@tcshStatementEnds
  54. " if statements
  55. syn keyword tcshIf nextgroup=tcshIfEnd skipwhite if
  56. syn region tcshIfEnd contained start='\S' skip='\\$' matchgroup=tcshBuiltin end='\v<then>|$' contains=@tcshConditions,tcshSpecial,@tcshStatementEnds
  57. syn region tcshIfEnd contained matchgroup=tcshBuiltin contains=@tcshConditions,tcshSpecial start='(' end='\v\)%(\s+then>)?' skipwhite nextgroup=@tcshStatementEnds
  58. syn region tcshIfEnd contained matchgroup=tcshBuiltin contains=tcshCommands,tcshSpecial start='\v\{\s+' end='\v\s+\}%(\s+then>)?' skipwhite nextgroup=@tcshStatementEnds keepend
  59. " else statements
  60. syn keyword tcshBuiltin nextgroup=tcshIf skipwhite else
  61. " while statements (contains expressions / operators)
  62. syn keyword tcshBuiltin nextgroup=@tcshConditions,tcshSpecial skipwhite while
  63. " Conditions (for if and while)
  64. syn region tcshParenExpr contained contains=@tcshConditions,tcshSpecial matchgroup=tcshBuiltin start='(' end=')'
  65. syn region tcshCmdSubst contained contains=tcshCommands matchgroup=tcshBuiltin start='\v\{\s+' end='\v\s+\}' keepend
  66. " Bindkey. Internal editor functions
  67. syn keyword tcshBindkeyFuncs contained backward-char backward-delete-char
  68. \ backward-delete-word backward-kill-line backward-word
  69. \ beginning-of-line capitalize-word change-case
  70. \ change-till-end-of-line clear-screen complete-word
  71. \ complete-word-fwd complete-word-back complete-word-raw
  72. \ copy-prev-word copy-region-as-kill dabbrev-expand delete-char
  73. \ delete-char-or-eof delete-char-or-list
  74. \ delete-char-or-list-or-eof delete-word digit digit-argument
  75. \ down-history downcase-word end-of-file end-of-line
  76. \ exchange-point-and-mark expand-glob expand-history expand-line
  77. \ expand-variables forward-char forward-word
  78. \ gosmacs-transpose-chars history-search-backward
  79. \ history-search-forward insert-last-word i-search-fwd
  80. \ i-search-back keyboard-quit kill-line kill-region
  81. \ kill-whole-line list-choices list-choices-raw list-glob
  82. \ list-or-eof load-average magic-space newline newline-and-hold
  83. \ newline-and-down-history normalize-path normalize-command
  84. \ overwrite-mode prefix-meta quoted-insert redisplay
  85. \ run-fg-editor run-help self-insert-command sequence-lead-in
  86. \ set-mark-command spell-word spell-line stuff-char
  87. \ toggle-literal-history transpose-chars transpose-gosling
  88. \ tty-dsusp tty-flush-output tty-sigintr tty-sigquit tty-sigtsusp
  89. \ tty-start-output tty-stop-output undefined-key
  90. \ universal-argument up-history upcase-word
  91. \ vi-beginning-of-next-word vi-add vi-add-at-eol vi-chg-case
  92. \ vi-chg-meta vi-chg-to-eol vi-cmd-mode vi-cmd-mode-complete
  93. \ vi-delprev vi-delmeta vi-endword vi-eword vi-char-back
  94. \ vi-char-fwd vi-charto-back vi-charto-fwd vi-insert
  95. \ vi-insert-at-bol vi-repeat-char-fwd vi-repeat-char-back
  96. \ vi-repeat-search-fwd vi-repeat-search-back vi-replace-char
  97. \ vi-replace-mode vi-search-back vi-search-fwd vi-substitute-char
  98. \ vi-substitute-line vi-word-back vi-word-fwd vi-undo vi-zero
  99. \ which-command yank yank-pop e_copy_to_clipboard
  100. \ e_paste_from_clipboard e_dosify_next e_dosify_prev e_page_up
  101. \ e_page_down
  102. syn keyword tcshBuiltin nextgroup=tcshBindkeyEnd bindkey
  103. syn region tcshBindkeyEnd contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$' contains=@tcshQuoteList,tcshComment,@tcshVarList,tcshMeta,tcshSpecial,tcshArgument,tcshBindkeyFuncs
  104. " Expressions start with @.
  105. syn match tcshExprStart '\v\@\s+' nextgroup=tcshExprVar
  106. syn match tcshExprVar contained '\v\h\w*%(\[\d+\])?' contains=tcshShellVar,tcshEnvVar nextgroup=tcshExprOp
  107. syn match tcshExprOp contained '++\|--'
  108. syn match tcshExprOp contained '\v\s*\=' nextgroup=tcshExprEnd
  109. syn match tcshExprEnd contained '\v.*$'hs=e+1 contains=@tcshConditions
  110. syn match tcshExprEnd contained '\v.{-};'hs=e contains=@tcshConditions
  111. " ----- Comments: ----- {{{1
  112. syn match tcshComment '#\s.*' contains=tcshTodo,tcshCommentTi,@Spell
  113. syn match tcshComment '\v#($|\S.*)' contains=tcshTodo,tcshCommentTi
  114. syn match tcshSharpBang '^#! .*$'
  115. syn match tcshCommentTi contained '\v#\s*\u\w*(\s+\u\w*)*:'hs=s+1 contains=tcshTodo
  116. syn match tcshTodo contained '\v\c<todo>'
  117. " ----- Strings ----- {{{1
  118. " Tcsh does not allow \" in strings unless the "backslash_quote" shell
  119. " variable is set. Set the vim variable "tcsh_backslash_quote" to 0 if you
  120. " want VIM to assume that no backslash quote constructs exist.
  121. " Backquotes are treated as commands, and are not contained in anything
  122. if exists('tcsh_backslash_quote') && tcsh_backslash_quote == 0
  123. syn region tcshSQuote keepend contained start="\v\\@<!'" end="'"
  124. syn region tcshDQuote keepend contained start='\v\\@<!"' end='"' contains=@tcshVarList,tcshSpecial,@Spell
  125. syn region tcshBQuote keepend start='\v\\@<!`' end='`' contains=@tcshStatements
  126. else
  127. syn region tcshSQuote contained start="\v\\@<!'" skip="\v\\\\|\\'" end="'"
  128. syn region tcshDQuote contained start='\v\\@<!"' end='"' contains=@tcshVarList,tcshSpecial,@Spell
  129. syn region tcshBQuote keepend matchgroup=tcshBQuoteGrp start='\v\\@<!`' skip='\v\\\\|\\`' end='`' contains=@tcshStatements
  130. endif
  131. " ----- Variables ----- {{{1
  132. " Variable Errors. Must come first! \$ constructs will be flagged by
  133. " tcshSpecial, so we don't consider them here.
  134. syn match tcshVarError '\v\$\S*' contained
  135. " Modifiable Variables without {}.
  136. syn match tcshUsrVar contained '\v\$\h\w*%(\[\d+%(-\d+)?\])?' nextgroup=@tcshModifiers contains=tcshShellVar,tcshEnvVar
  137. syn match tcshArgv contained '\v\$%(\d+|\*)' nextgroup=@tcshModifiers
  138. " Modifiable Variables with {}.
  139. syn match tcshUsrVar contained '\v\$\{\h\w*%(\[\d+%(-\d+)?\])?%(:\S*)?\}' contains=@tcshModifiers,tcshShellVar,tcshEnvVar
  140. syn match tcshArgv contained '\v\$\{%(\d+|\*)%(:\S*)?\}' contains=@tcshModifiers
  141. " Un-modifiable Substitutions. Order is important here.
  142. syn match tcshSubst contained '\v\$[?#$!_<]' nextgroup=tcshModifierError
  143. syn match tcshSubst contained '\v\$[%#?]%(\h\w*|\d+)' nextgroup=tcshModifierError contains=tcshShellVar,tcshEnvVar
  144. syn match tcshSubst contained '\v\$\{[%#?]%(\h\w*|\d+)%(:\S*)?\}' contains=tcshModifierError contains=tcshShellVar,tcshEnvVar
  145. " Variable Name Expansion Modifiers (order important)
  146. syn match tcshModifierError contained '\v:\S*'
  147. syn match tcshModifier contained '\v:[ag]?[htreuls&qx]' nextgroup=@tcshModifiers
  148. " ----- Operators / Specials ----- {{{1
  149. " Standard redirects (except <<) [<, >, >>, >>&, >>!, >>&!]
  150. syn match tcshRedir contained '\v\<|\>\>?\&?!?'
  151. " Meta-chars
  152. syn match tcshMeta contained '\v[]{}*?[]'
  153. " Here documents (<<)
  154. syn region tcshHereDoc contained matchgroup=tcshShellVar start='\v\<\<\s*\z(\h\w*)' end='^\z1$' contains=@tcshVarList,tcshSpecial
  155. syn 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$'
  156. " Operators
  157. syn match tcshOperator contained '&&\|!\~\|!=\|<<\|<=\|==\|=\~\|>=\|>>\|\*\|\^\|\~\|||\|!\|%\|&\|+\|-\|/\|<\|>\||'
  158. "syn match tcshOperator contained '[(){}]'
  159. " Numbers
  160. syn match tcshNumber contained '\v<-?\d+>'
  161. " Arguments
  162. syn match tcshArgument contained '\v\s@<=-(\w|-)*'
  163. " Special characters. \xxx, or backslashed characters.
  164. "syn match tcshSpecial contained '\v\\@<!\\(\d{3}|.)'
  165. syn match tcshSpecial contained '\v\\%([0-7]{3}|.)'
  166. " ----- Synchronising ----- {{{1
  167. if exists('tcsh_minlines')
  168. if tcsh_minlines == 'fromstart'
  169. syn sync fromstart
  170. else
  171. exec 'syn sync minlines=' . tcsh_minlines
  172. endif
  173. else
  174. syn sync minlines=100 " Some completions can be quite long
  175. endif
  176. " ----- Highlighting ----- {{{1
  177. " Define highlighting of syntax groups
  178. hi def link tcshError Error
  179. hi def link tcshBuiltin Statement
  180. hi def link tcshShellVar Preproc
  181. hi def link tcshEnvVar tcshShellVar
  182. hi def link tcshAliases tcshShellVar
  183. hi def link tcshAliCmd Identifier
  184. hi def link tcshCommands Identifier
  185. hi def link tcshIf tcshBuiltin
  186. hi def link tcshWhile tcshBuiltin
  187. hi def link tcshBindkeyFuncs Function
  188. hi def link tcshExprStart tcshBuiltin
  189. hi def link tcshExprVar tcshUsrVar
  190. hi def link tcshExprOp tcshOperator
  191. hi def link tcshExprEnd tcshOperator
  192. hi def link tcshComment Comment
  193. hi def link tcshCommentTi Preproc
  194. hi def link tcshSharpBang tcshCommentTi
  195. hi def link tcshTodo Todo
  196. hi def link tcshSQuote Constant
  197. hi def link tcshDQuote tcshSQuote
  198. hi def link tcshBQuoteGrp Include
  199. hi def link tcshVarError Error
  200. hi def link tcshUsrVar Type
  201. hi def link tcshArgv tcshUsrVar
  202. hi def link tcshSubst tcshUsrVar
  203. hi def link tcshModifier tcshArgument
  204. hi def link tcshModifierError tcshVarError
  205. hi def link tcshMeta tcshSubst
  206. hi def link tcshRedir tcshOperator
  207. hi def link tcshHereDoc tcshSQuote
  208. hi def link tcshOperator Operator
  209. hi def link tcshNumber Number
  210. hi def link tcshArgument Special
  211. hi def link tcshSpecial SpecialChar
  212. " }}}
  213. let &cpo = s:oldcpo
  214. unlet s:oldcpo
  215. let b:current_syntax = 'tcsh'
  216. " vim: nowrap sw=2 sts=2 ts=8 noet fdm=marker: