" Vim syntax file
" Language:	Z shell (zsh)
" Maintainer:	Felix von Leitner
" Heavily based on sh.vim by Lennart Schultz
" Last change:	1997 April 26

" Remove any old syntax stuff hanging around
syntax clear

syntax region	zshSinglequote	start=+'+ skip=+\\'+ end=+'+ 
" A bunch of useful zsh keywords
" syntax keyword	zshFunction	function
syntax keyword	zshStatement	bg break cd chdir continue echo eval exec 
syntax keyword	zshStatement	exit export fg getopts hash jobs kill 
syntax keyword	zshStatement	pwd read readonly return set zshift function
syntax keyword	zshStatement	stop suspend test times trap type ulimit
syntax keyword	zshStatement	umask unset wait setopt compctl . source
syntax keyword	zshConditional	if else esac case then elif fi in
syntax keyword	zshRepeat	while for do done

syntax match	zshIdentifier	"\<[a-zA-Z_][a-zA-Z0-9_]*\>"
" Following is worth to notice: command substitution, file redirection and functions (so these features turns red)
syntax match	zshFunctionName	"[a-zA-Z_][a-zA-Z0-9_]*[ 	]*()"
syntax region	zshCommandSub	start=+`+ skip=+\\`+ end=+`+ 
" contains ALLBUT zshFunction
syntax match	zshRedir	"[0-9]\=\(<\|<<\|>\|>>\)\(|\|&[0-9]\)\="

syntax keyword	zshTodo contained TODO

syntax keyword	zshShellVariables	USER LOGNAME HOME PATH CDPATH SHELL
syntax keyword	zshShellVariables	LC_TYPE LC_MESSAGE MAIL MAILCHECK
syntax keyword	zshShellVariables	PS1 PS2 IFS EGID EUID ERRNO GID UID
syntax keyword	zshShellVariables	HOST LINENO MACHTYPE OLDPWD OPTARG 
syntax keyword	zshShellVariables	OPTIND OSTYPE PPID PWD RANDOM SECONDS
syntax keyword	zshShellVariables	SHLVL TTY signals TTYIDLE USERNAME 
syntax keyword	zshShellVariables	VENDOR ZSH_NAME ZSH_VERSION ARGV0
syntax keyword	zshShellVariables	BAUD COLUMNS cdpath DIRSTACKSIZE
syntax keyword	zshShellVariables	FCEDIT fignore fpath histchars HISTCHARS
syntax keyword	zshShellVariables	HISTFILE HISTSIZE KEYTIMEOUT LANG
syntax keyword	zshShellVariables	LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES
syntax keyword	zshShellVariables	LC_TIME LINES LISTMAX LOGCHECK mailpath
syntax keyword	zshShellVariables	MAILPATH MANPATH manpath module_path
syntax keyword	zshShellVariables	MODULE_PATH NULLCMD path POSTEDIT
syntax keyword	zshShellVariables	PS3 PS4 PROMPT PROMPT2 PROMPT3 PROMPT4
syntax keyword	zshShellVariables	psvar PSVAR prompt READNULLCMD
syntax keyword	zshShellVariables	REPORTTIME RPROMPT RPS1 SAVEHIST
syntax keyword	zshShellVariables	SPROMPT STTY TIMEFMT TMOUT TMPPREFIX
syntax keyword	zshShellVariables	watch WATCH WATCHFMT WORDCHARS ZDOTDIR
syntax match	zshSpecialShellVar	"\$[-#@*$?!0-9]" 
syntax keyword	zshSetVariables		ignoreeof noclobber
syntax region	zshDerefOpr	start="\${" end="}" contains zshShellVariables
syntax match	zshDerefIdentifier	"\$[a-zA-Z_][a-zA-Z0-9_]*\>"
syntax match	zshOperator		"[][}{&;|)(]"

" String and Character contstants
" Highlight special characters (those which have a backslash) differently
syntax match   zshSpecial	contained "\\[0-9][0-9][0-9]\|\\[abcfnrtv\\]"


syntax match  zshNumber		"-\=\<[0-9]\+\>"
syntax match  zshComment	"#.*$" contains zshNumber zshTodo 


syntax match zshTestOpr	"-\<[oeaznlg][tfqet]\=\>\|!\==\|-\<[b-gkLprsStuwjxOG]\>"
"syntax region zshTest           start="\[" skip="\\$" end="\]" contains zshString zshTestOpr zshDerefIdentifier zshDerefOpr
syntax region  zshString	start=+"+  skip=+\\"+  end=+"+  contains zshSpecial zshOperator zshDerefIdentifier zshDerefOpr zshSpecialShellVar zshSinglequote zshCommandSub

if !exists("did_sh_syntax_inits")
  let did_sh_syntax_inits = 1
  " The default methods for highlighting.  Can be overridden later
  highlight link zshSinglequote		zshString
  highlight link zshConditional		zshStatement
  highlight link zshRepeat		zshStatement
  highlight link zshFunctionName	zshFunction
  highlight link zshCommandSub		zshOperator
  highlight link zshRedir		zshOperator
  highlight link zshSetVariables	zshShellVariables
  highlight link zshSpecialShellVar	zshShellVariables
  highlight link zshTestOpr		zshOperator
  highlight link zshDerefOpr		zshSpecial
  highlight link zshDerefIdentifier	zshShellVariables
  highlight link zshOperator		Operator
  highlight link zshStatement		Statement
  highlight link zshNumber		Number
  highlight link zshString		String
  highlight link zshComment		Comment
  highlight link zshSpecial		Special
  highlight link zshTodo		Todo
  highlight link zshIdentifier		Identifier
  highlight link zshShellVariables	Special
"  highlight zshOperator		term=underline ctermfg=6 guifg=Purple gui=bold
"  highlight zshShellVariables	term=underline ctermfg=2 guifg=SeaGreen gui=bold
"  highlight zshFunction		term=bold ctermbg=1 guifg=Red
endif
