📄 perl.vim
字号:
" Vim syntax file" Language: Perl" Maintainer: Nick Hibma <n_hibma@webweaving.org>" Last Change: 2001 May 10" Location: http://www.etla.net/~n_hibma/vim/syntax/perl.vim"" Please download most recent version first before mailing" any comments." See also the file perl.vim.regression.pl to check whether your" modifications work in the most odd cases" http://www.etla.net/~n_hibma/vim/syntax/perl.vim.regression.pl"" Original version: Sonia Heimann <niania@netsurf.org>" Thanks to many people for their contribution. They made it work, not me." The following parameters are available for tuning the" perl syntax highlighting, with defaults given:"" unlet perl_include_pod" unlet perl_want_scope_in_variables" unlet perl_extended_vars" unlet perl_string_as_statement" unlet perl_no_sync_on_sub" unlet perl_no_sync_on_global_var" let perl_sync_dist = 100" unlet perl_fold" Remove any old syntax stuff that was loaded (5.x) or quit when a syntax file" was already loaded (6.x).if version < 600 syntax clearelseif exists("b:current_syntax") finishendif" Unset perl_fold if it set but vim doesn't support it.if version < 600 && exists("perl_fold") unlet perl_foldendif" POD starts with ^=<word> and ends with ^=cutif exists("perl_include_pod") " Include a while extra syntax file syn include @Pod <sfile>:p:h/pod.vim unlet b:current_syntax syn region perlPOD start="^=[a-z]" end="^=cut" contains=@Pod,perlTodo keependelse " Use only the bare minimum of rules syn region perlPOD start="^=[a-z]" end="^=cut"endif" All keywords"syn keyword perlConditional if elsif unless switch eq ne gt lt ge le cmp not and or xorsyn keyword perlConditional else nextgroup=perlElseIfError skipwhite skipnl skipemptysyn keyword perlRepeat while for foreach do untilsyn keyword perlOperator defined undef and or not bless refif exists("perl_fold") " in Vim if BEGIN/END is a keyword the perlBEGINENDFold does not work syn match perlControl "BEGIN" contained syn match perlControl "END" containedelse syn keyword perlControl BEGIN ENDendifsyn keyword perlStatementStorage my local oursyn keyword perlStatementControl goto return last next continue redosyn keyword perlStatementScalar chomp chop chr crypt index lc lcfirst length ord pack reverse rindex sprintf substr uc ucfirstsyn keyword perlStatementRegexp pos quotemeta split studysyn keyword perlStatementNumeric abs atan2 cos exp hex int log oct rand sin sqrt srandsyn keyword perlStatementList splice unshift shift push pop split join reverse grep map sort unpacksyn keyword perlStatementHash each exists keys values tie tiedsyn keyword perlStatementIOfunc carp confess croak dbmclose dbmopen die syscallsyn keyword perlStatementFiledesc binmode close closedir eof fileno getc lstat print printf readdir rewinddir select stat tell telldir write nextgroup=perlFiledescStatementNocommasyn keyword perlStatementFiledesc fcntl flock ioctl open opendir read seek seekdir sysopen sysread sysseek syswrite truncate nextgroup=perlFiledescStatementCommasyn keyword perlStatementVector pack vecsyn keyword perlStatementFiles chdir chmod chown chroot glob link mkdir readlink rename rmdir symlink umask unlink utimesyn match perlStatementFiles "-[rwxoRWXOezsfdlpSbctugkTBMAC]\>"syn keyword perlStatementFlow caller die dump eval exit wantarraysyn keyword perlStatementInclude requiresyn match perlStatementInclude "\(use\|no\)\s\+\(integer\>\|strict\>\|lib\>\|sigtrap\>\|subs\>\|vars\>\|warnings\>\|utf8\>\|byte\>\)\="syn keyword perlStatementScope importsyn keyword perlStatementProc alarm exec fork getpgrp getppid getpriority kill pipe setpgrp setpriority sleep system times wait waitpidsyn keyword perlStatementSocket accept bind connect getpeername getsockname getsockopt listen recv send setsockopt shutdown socket socketpairsyn keyword perlStatementIPC msgctl msgget msgrcv msgsnd semctl semget semop shmctl shmget shmread shmwritesyn keyword perlStatementNetwork endprotoent endservent gethostbyaddr gethostbyname gethostent getnetbyaddr getnetbyname getnetent getprotobyname getprotobynumber getprotoent getservbyname getservbyport getservent sethostent setnetent setprotoent setserventsyn keyword perlStatementPword getpwuid getpwnam getpwent setpwent endpwent getgrent getgrgidsyn keyword perlStatementTime gmtime localtime time timessyn keyword perlStatementMisc warn formline reset scalar new deletesyn keyword perlTodo TODO TBD FIXME XXX contained" Perl Identifiers."" Should be cleaned up to better handle identifiers in particular situations" (in hash keys for example)"" Plain identifiers: $foo, @foo, $#foo, %foo, &foo and dereferences $$foo, @$foo, etc." We do not process complex things such as @{${"foo"}}. Too complicated, and" too slow. And what is after the -> is *not* considered as part of the" variable - there again, too complicated and too slow." Special variables first ($^A, ...) and ($|, $', ...)syn match perlVarPlain "$^[ADEFHILMOPSTWX]\="syn match perlVarPlain "$[\\\"\[\]'&`+*.,;=%~!?@$<>(0-9-]"" Same as above, but avoids confusion in $::foo (equivalent to $main::foo)syn match perlVarPlain "$:[^:]"" These variables are not recognized within matches.syn match perlVarNotInMatches "$[|)]"" This variable is not recognized within matches delimited by m//.syn match perlVarSlash "$/"" And plain identifierssyn match perlPackageRef "\(\h\w*\)\=\(::\|'\)\I"me=e-1 contained" To highlight packages in variables as a scope reference - i.e. in $pack::var," pack:: is a scope, just set "perl_want_scope_in_variables"" If you *want* complex things like @{${"foo"}} to be processed," just set the variable "perl_extended_vars"..." FIXME value between {} should be marked as string. is treated as such by Perl." At the moment it is marked as something greyish instead of read. Probably todo" with transparency. Or maybe we should handle the bare word in that case. or make it intoif exists("perl_want_scope_in_variables") syn match perlVarPlain "\\\=\([@%$]\|\$#\)\$*\(\I\i*\)\=\(\(::\|'\)\I\i*\)*\>" contains=perlPackageRef nextgroup=perlVarMember,perlVarSimpleMember syn match perlFunctionName "\\\=&\$*\(\I\i*\)\=\(\(::\|'\)\I\i*\)*\>" contains=perlPackageRef nextgroup=perlVarMember,perlVarSimpleMemberelse syn match perlVarPlain "\\\=\([@%$]\|\$#\)\$*\(\I\i*\)\=\(\(::\|'\)\I\i*\)*\>" nextgroup=perlVarMember,perlVarSimpleMember syn match perlFunctionName "\\\=&\$*\(\I\i*\)\=\(\(::\|'\)\I\i*\)*\>" nextgroup=perlVarMember,perlVarSimpleMemberendifif exists("perl_extended_vars") syn cluster perlExpr contains=perlStatementScalar,perlStatementRegexp,perlStatementNumeric,perlStatementList,perlStatementHash,perlStatementFiles,perlStatementTime,perlStatementMisc,perlVarPlain,perlVarNotInMatches,perlVarSlash,perlVarBlock,perlShellCommand,perlNumber,perlStringUnexpanded,perlString,perlQQ syn region perlVarBlock matchgroup=perlVarPlain start="\($#\|[@%\$]\){" skip="\\}" end="}" contains=@perlExpr nextgroup=perlVarMember,perlVarSimpleMember syn match perlVarPlain "\\\=\(\$#\|[@%&$]\)\$*{\I\i*}" nextgroup=perlVarMember,perlVarSimpleMember syn region perlVarMember matchgroup=perlVarPlain start="\(->\)\={" skip="\\}" end="}" contained contains=@perlExpr nextgroup=perlVarMember,perlVarSimpleMember syn match perlVarSimpleMember "\(->\)\={\I\i*}" nextgroup=perlVarMember,perlVarSimpleMember contains=perlVarSimpleMemberName contained syn match perlVarSimpleMemberName "\I\i*" contained syn region perlVarMember matchgroup=perlVarPlain start="\(->\)\=\[" skip="\\]" end="]" contained contains=@perlExpr nextgroup=perlVarMember,perlVarSimpleMemberendif" File Descriptorssyn match perlFiledescRead "[<]\h\w\+[>]"syn match perlFiledescStatementComma "\s*(\=\s*\h\w*\>\s*," transparent contained contains=perlFiledescStatementsyn match perlFiledescStatementNocomma "\s*(\=\s*\h\w*\>\s\+[^,]"me=e-1 transparent contained contains=perlFiledescStatementsyn match perlFiledescStatement "\h\w\+" contained" Special characters in strings and matchessyn match perlSpecialString "\\\(\d\+\|[xX]\x\+\|c\u\|.\)" containedsyn match perlSpecialStringU "\\['\\]" containedsyn match perlSpecialMatch "{\d\(,\d\)\=}" containedsyn match perlSpecialMatch "\[\(\]\|-\)\=[^\[\]]*\(\[\|\-\)\=\]" containedsyn match perlSpecialMatch "[+*()?.]" containedsyn match perlSpecialMatch "(?[#:=!]" containedsyn match perlSpecialMatch "(?[imsx]\+)" contained" FIXME the line below does not work. It should mark end of line and" begin of line as perlSpecial." syn match perlSpecialBEOM "^\^\|\$$" contained" Possible errors"" Highlight lines with only whitespace (only in blank delimited here documents) as errorssyn match perlNotEmptyLine "^\s\+$" contained" Highlight '} else if (...) {', it should be '} else { if (...) { ' or" '} elsif (...) {'.syn keyword perlElseIfError if contained" Variable interpolation"" These items are interpolated inside "" strings and similar constructs.syn cluster perlInterpDQ contains=perlSpecialString,perlVarPlain,perlVarNotInMatches,perlVarSlash,perlVarBlock" These items are interpolated inside '' strings and similar constructs.syn cluster perlInterpSQ contains=perlSpecialStringU" These items are interpolated inside m// matches and s/// substitutions.syn cluster perlInterpSlash contains=perlSpecialString,perlSpecialMatch,perlVarPlain,perlVarBlock,perlSpecialBEOM" These items are interpolated inside m## matches and s### substitutions.syn cluster perlInterpMatch contains=@perlInterpSlash,perlVarSlash" Shell commandssyn region perlShellCommand matchgroup=perlMatchStartEnd start="`" end="`" contains=@perlInterpDQ" Constants"" Numberssyn match perlNumber "[-+]\=\(\<\d[[:digit:]_]*\(L\=\|[eE][\-+]\=\d\+\)\>\|0[xX]\x[[:xdigit:]_]*\>\)"" Simple version of searches and matches" caters for m//, m## and m[] (and the !/ variant)syn region perlMatch matchgroup=perlMatchStartEnd start=+[m!]/+ end=+/[cgimosx]*+ contains=@perlInterpSlashsyn region perlMatch matchgroup=perlMatchStartEnd start=+[m!]#+ end=+#[cgimosx]*+ contains=@perlInterpMatchsyn region perlMatch matchgroup=perlMatchStartEnd start=+[m!]\[+ end=+\][cgimosx]*+ contains=@perlInterpMatch" A special case for m!!x which allows for comments and extra whitespace in the patternsyn region perlMatch matchgroup=perlMatchStartEnd start=+[m!]!+ end=+![cgimosx]*+ contains=@perlInterpSlash,perlComment" Below some hacks to recognise the // variant. This is virtually impossible to catch in all" cases as the / is used in so many other ways, but these should be the most obvious ones.syn region perlMatch matchgroup=perlMatchStartEnd start=+^split /+lc=5 start=+[^$@%]\<split /+lc=6 start=+^if /+lc=2 start=+[^$@%]if /+lc=3 start=+[!=]\~\s*/+lc=2 start=+[(~]/+lc=1 start=+\.\./+lc=2 start=+\s/[^= \t0-9$@%]+lc=1,me=e-1,rs=e-1 start=+^/+ skip=+\\/+ end=+/[cgimosx]*+ contains=@perlInterpSlash" Substitutions" caters for s///, s### and s[][]" perlMatch is the first part, perlSubstitution* is the substitution partsyn region perlMatch matchgroup=perlMatchStartEnd start=+\<s'+ end=+'+me=e-1 contains=@perlInterpSQ nextgroup=perlSubstitutionSQsyn region perlMatch matchgroup=perlMatchStartEnd start=+\<s"+ end=+"+me=e-1 contains=@perlInterpMatch nextgroup=perlSubstitutionDQsyn region perlMatch matchgroup=perlMatchStartEnd start=+\<s/+ end=+/+me=e-1 contains=@perlInterpSlash nextgroup=perlSubstitutionSlashsyn region perlMatch matchgroup=perlMatchStartEnd start=+\<s#+ end=+#+me=e-1 contains=@perlInterpMatch nextgroup=perlSubstitutionHashsyn region perlMatch matchgroup=perlMatchStartEnd start=+\<s\[+ end=+\]+ contains=@perlInterpMatch nextgroup=perlSubstitutionBracket skipwhite skipempty skipnlsyn region perlMatch matchgroup=perlMatchStartEnd start=+\<s{+ end=+}+ contains=@perlInterpMatch nextgroup=perlSubstitutionCurly skipwhite skipempty skipnlsyn region perlSubstitutionSQ matchgroup=perlMatchStartEnd start=+'+ end=+'[ecgimosx]*+ contained contains=@perlInterpSQsyn region perlSubstitutionDQ matchgroup=perlMatchStartEnd start=+"+ end=+"[ecgimosx]*+ contained contains=@perlInterpDQsyn region perlSubstitutionSlash matchgroup=perlMatchStartEnd start=+/+ end=+/[ecgimosx]*+ contained contains=@perlInterpDQsyn region perlSubstitutionHash matchgroup=perlMatchStartEnd start=+#+ end=+#[ecgimosx]*+ contained contains=@perlInterpDQsyn region perlSubstitutionBracket matchgroup=perlMatchStartEnd start=+\[+ end=+\][ecgimosx]*+ contained contains=@perlInterpDQsyn region perlSubstitutionCurly matchgroup=perlMatchStartEnd start=+{+ end=+}[ecgimosx]*+ contained contains=@perlInterpDQ" A special case for m!!x which allows for comments and extra whitespace in the patternsyn region perlMatch matchgroup=perlMatchStartEnd start=+\<s!+ end=+!+me=e-1 contains=@perlInterpSlash,perlComment nextgroup=perlSubstitutionPlingsyn region perlSubstitutionPling matchgroup=perlMatchStartEnd start=+!+ end=+![ecgimosx]*+ contained contains=@perlInterpDQ" Substitutions" caters for tr///, tr### and tr[][]" perlMatch is the first part, perlTranslation* is the second, translator part.syn region perlMatch matchgroup=perlMatchStartEnd start=+\<\(tr\|y\)'+ end=+'+me=e-1 contains=@perlInterpSQ nextgroup=perlTranslationSQsyn region perlMatch matchgroup=perlMatchStartEnd start=+\<\(tr\|y\)"+ end=+"+me=e-1 contains=@perlInterpSQ nextgroup=perlTranslationDQsyn region perlMatch matchgroup=perlMatchStartEnd start=+\<\(tr\|y\)/+ end=+/+me=e-1 contains=@perlInterpSQ nextgroup=perlTranslationSlashsyn region perlMatch matchgroup=perlMatchStartEnd start=+\<\(tr\|y\)#+ end=+#+me=e-1 contains=@perlInterpSQ nextgroup=perlTranslationHashsyn region perlMatch matchgroup=perlMatchStartEnd start=+\<\(tr\|y\)\[+ end=+\]+ contains=@perlInterpSQ nextgroup=perlTranslationBracket skipwhite skipempty skipnlsyn region perlMatch matchgroup=perlMatchStartEnd start=+\<\(tr\|y\){+ end=+}+ contains=@perlInterpSQ nextgroup=perlTranslationCurly skipwhite skipempty skipnlsyn region perlTranslationSQ matchgroup=perlMatchStartEnd start=+'+ end=+'[cds]*+ containedsyn region perlTranslationDQ matchgroup=perlMatchStartEnd start=+"+ end=+"[cds]*+ containedsyn region perlTranslationSlash matchgroup=perlMatchStartEnd start=+/+ end=+/[cds]*+ containedsyn region perlTranslationHash matchgroup=perlMatchStartEnd start=+#+ end=+#[cds]*+ containedsyn region perlTranslationBracket matchgroup=perlMatchStartEnd start=+\[+ end=+\][cds]*+ containedsyn region perlTranslationCurly matchgroup=perlMatchStartEnd start=+{+ end=+}[cds]*+ contained" The => operator forces a bareword to the left of it to be interpreted as" a stringsyn match perlString "\<\I\i*\s*=>"me=e-2" Strings and q, qq, qw and qr expressions" Brackets in qq()syn region perlBrackets start=+(+ end=+)+ contained transparent contains=perlBrackets,@perlStringSQ
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -