2015-07-13 21 views
2

我在使用的語法文件中遇到問題,它在括號之後突出顯示方法調用,就好像它們是類型/類一樣。Vim C#語法突出顯示方法調用,就好像它們是類型

enter image description here

我找到負責該行:

syn match csClass contained  /\<[A-Z][a-z]\w\+/ nextgroup=csGeneric 

證據是,如果我從這個組中刪除csClass,我沒有得到凸顯在畫面中突出顯示的方法:

syn region csEnclosed start="(" end=")" contains=csConstant, csType, csString, csVerbatimString, csCharacter, csNumber, csIface, csClass 

以下是完整的cs.vim文件:

" Vim syntax file 
" Language:    Microsoft C# 
" Maintainer:   Kian Ryan ([email protected]) 
" Former Maintainer: Anduin Withers ([email protected]) 
" Filenames:   *.cs 
" 
" REFERENCES: 
" [1] ECMA TC39: C# Language Specification (WD13Oct01.doc) 

if exists("b:current_syntax") 
    finish 
endif 

let s:cs_cpo_save = &cpo 
set cpo&vim 

" type 
syn keyword csType   bool byte char decimal double float int long object sbyte short string uint ulong ushort void var dynamic 
" storage 
syn keyword csTypeDecleration   class enum struct nextgroup=csClass skipwhite 
syn keyword csStorage   delegate interface namespace struct 
syn keyword csInterfaceDecleration  interface nextgroup=csIface skipwhite 
" repeat/condition/label 
syn keyword csRepeat   break continue do for foreach goto return while 
syn keyword csConditional  else if switch 
syn keyword csLabel   case default 
" :: is usually an error in C#, except for the special case of "global::" 
syn match csOperatorError  display +::+ 
syn match csGlobal   display +global::+ 
" user labels (see [1] 8.6 Statements) 
syn match csLabel   display +^\s*\I\i*\s*:\([^:]\)\@=+ 
" modifier 
syn keyword csModifier   abstract const extern internal override private protected public readonly sealed static virtual volatile nextgroup=CsClass,CsIface skipwhite 
" constant 
syn keyword csConstant   false null true 
" exception 
syn keyword csException   try catch finally throw 

" TODO: 
syn keyword csUnspecifiedStatement as base checked event fixed in is lock operator out params ref sizeof stackalloc this unchecked unsafe using 
" TODO: 
syn keyword csUnsupportedStatement add remove value 
" TODO: 
syn keyword csUnspecifiedKeyword explicit implicit 

syn keyword csTypeOf     typeof nextgroup=csEnclosed 

" Linq Keywords 
"syn keyword csLinq      from where select group into orderby join let in on equals by ascending descending 

" Async Keywords 
syn keyword csAsync      async await 

" Contextual Keywords 
syn match csContextualStatement /\<yield[[:space:]\n]\+\(return\|break\)/me=s+5 
syn match csContextualStatement /\<partial[[:space:]\n]\+\(class\|struct\|interface\)/me=s+7 
syn match csContextualStatement /\<\(get\|set\);/me=s+3 
syn match csContextualStatement /\<\(get\|set\)[[:space:]\n]*{/me=s+3 
syn match csContextualStatement /\<where\>[^:]\+:/me=s+5 

"New Declerations 
syn keyword csNewDecleration   new nextgroup=csClass skipwhite 

"Interface & Class Identifier 
syn match csClass contained  /\<[A-Z][a-z]\w\+/ nextgroup=csGeneric 
syn match csIface contained  /\<I[A-Z][a-z]\w\+/ nextgroup=csGeneric 
" syn region csGeneric start="<" end=">" contains=csIface,csClass 
syn region csEnclosed start="(" end=")" contains=csConstant,csType,csString, csVerbatimString, csCharacter, csNumber,csIface,csClass 
"syn region csInherits start=":" end="{" contains=csIface,csClass 

" Attributes 
syn region csAttribute start="^\s*\[" end="\]\s*" contains=csString, csVerbatimString, csCharacter, csNumber, csType 


" Comments 
" 
" PROVIDES: @csCommentHook 
" 
" TODO: include strings ? 
" 
syn keyword csTodo  contained TODO FIXME XXX NOTE 
syn region csComment  start="/\*" end="\*/" [email protected],csTodo,@Spell 
syn match csComment  "//.*$" [email protected],csTodo,@Spell 

" xml markup inside '///' comments 
syn cluster xmlRegionHook add=csXmlCommentLeader 
syn cluster xmlCdataHook add=csXmlCommentLeader 
syn cluster xmlStartTagHook add=csXmlCommentLeader 
syn keyword csXmlTag  contained Libraries Packages Types Excluded ExcludedTypeName ExcludedLibraryName 
syn keyword csXmlTag  contained ExcludedBucketName TypeExcluded Type TypeKind TypeSignature AssemblyInfo 
syn keyword csXmlTag  contained AssemblyName AssemblyPublicKey AssemblyVersion AssemblyCulture Base 
syn keyword csXmlTag  contained BaseTypeName Interfaces Interface InterfaceName Attributes Attribute 
syn keyword csXmlTag  contained AttributeName Members Member MemberSignature MemberType MemberValue 
syn keyword csXmlTag  contained ReturnValue ReturnType Parameters Parameter MemberOfPackage 
syn keyword csXmlTag  contained ThreadingSafetyStatement Docs devdoc example overload remarks returns summary 
syn keyword csXmlTag  contained threadsafe value internalonly nodoc exception param permission platnote 
syn keyword csXmlTag  contained seealso b c i pre sub sup block code note paramref see subscript superscript 
syn keyword csXmlTag  contained list listheader item term description altcompliant altmember 

syn cluster xmlTagHook add=csXmlTag 

syn match csXmlCommentLeader +\/\/\/+ contained 
syn match csXmlComment +\/\/\/.*$+ contains=csXmlCommentLeader,@csXml,@Spell 
syntax include @csXml syntax/xml.vim 
hi def link xmlRegion Comment 


" [1] 9.5 Pre-processing directives 
syn region csPreCondit 
    \ start="^\s*#\s*\(define\|undef\|if\|elif\|else\|endif\|line\|error\|warning\)" 
    \ skip="\\$" end="$" contains=csComment keepend 
syn region csRegion matchgroup=csPreCondit start="^\s*#\s*region.*$" 
    \ end="^\s*#\s*endregion" transparent fold contains=TOP 

syn region csFold start="{" end="}" transparent fold 

" Strings and constants 
syn match csSpecialError contained "\\." 
syn match csSpecialCharError contained "[^']" 
" [1] 9.4.4.4 Character literals 
syn match csSpecialChar contained +\\["\\'0abfnrtvx]+ 
" unicode characters 
syn match csUnicodeNumber +\\\(u\x\{4}\|U\x\{8}\)+ contained contains=csUnicodeSpecifier 
syn match csUnicodeSpecifier +\\[uU]+ contained 
syn region csVerbatimString [email protected]"+ end=+"+ skip=+""+ contains=csVerbatimSpec,@Spell 
syn match csVerbatimSpec [email protected]"+he=s+1 contained 
syn region csString  start=+"+ end=+"+ end=+$+ contains=csSpecialChar,csSpecialError,csUnicodeNumber,@Spell 
syn match csCharacter  "'[^']*'" contains=csSpecialChar,csSpecialCharError 
syn match csCharacter  "'\\''" contains=csSpecialChar 
syn match csCharacter  "'[^\\]'" 
syn match csNumber  "\<\(0[0-7]*\|0[xX]\x\+\|\d\+\)[lL]\=\>" 
syn match csNumber  "\(\<\d\+\.\d*\|\.\d\+\)\([eE][-+]\=\d\+\)\=[fFdD]\=" 
syn match csNumber  "\<\d\+[eE][-+]\=\d\+[fFdD]\=\>" 
syn match csNumber  "\<\d\+\([eE][-+]\=\d\+\)\=[fFdD]\>" 

" The default highlighting. 
hi def link csType   Type 
hi def link csTypeDecleration  StorageClass 
hi def link csInterfaceDecleration  StorageClass 
hi def link csNewDecleration   StorageClass 
hi def link csStorage   StorageClass 
hi def link csRepeat   Repeat 
hi def link csConditional  Conditional 
hi def link csLabel   Label 
hi def link csModifier   StorageClass 
hi def link csConstant   Constant 
hi def link csException   Exception 
hi def link csUnspecifiedStatement Statement 
hi def link csUnsupportedStatement Statement 
hi def link csUnspecifiedKeyword Keyword 
"hi def link csLinq      Keyword 
hi def link csAsync      Keyword 
hi def link csContextualStatement Statement 
hi def link csOperatorError  Error 
hi def link csAttribute   PreProc 

hi def link csIface      Type 
hi def link csClass      Type 

hi def link csTodo   Todo 
hi def link csComment   Comment 

hi def link csSpecialError  Error 
hi def link csSpecialCharError  Error 
hi def link csString   String 
hi def link csVerbatimString  String 
hi def link csVerbatimSpec  SpecialChar 
hi def link csPreCondit   PreCondit 
hi def link csCharacter   Character 
hi def link csSpecialChar  SpecialChar 
hi def link csNumber   Number 
hi def link csUnicodeNumber  SpecialChar 
hi def link csUnicodeSpecifier  SpecialChar 
hi def link csTypeOf     Keyword 

" xml markup 
hi def link csXmlCommentLeader  Comment 
hi def link csXmlComment  Comment 
hi def link csXmlTag   Statement 

let b:current_syntax = "cs" 

let &cpo = s:cs_cpo_save 
unlet s:cs_cpo_save 

我想如果我可以去csClass比賽,並試圖告訴它它不應該以點開始。它應該修復它,對吧?但我不熟悉vim的正則表達式(我使用常規正則表達式)。我嘗試這樣做:

syn match csClass contained  /^[^\.]\<[A-Z][a-z]\w\+/ nextgroup=csGeneric 

的意圖是否定.(不應.開始),但它沒有工作,它禁用所有的類突出。

什麼是實現這一目標的正確途徑?

非常感謝幫助!

+1

嘗試刪除字符串錨的開始:'/ [^。] \ <[A-Z] [a-z] \ w \ + /'。請注意,不幸的是,VIM中沒有環視。 –

+0

天才!有效!但你能解釋一下嗎? (也轉換爲答案) – vexe

+0

@stribizhev _注意,在VIM中沒有環視,不幸的是。 - 當然有,從這裏開始:':help \ @ ='。試試':help \ zs'和':help \ ze'。這些組合比大多數其他語言提供的更有用。 – lcd047

回答

1

您可以使用

/[^.]\<[A-Z][a-z]\w\+/ 

由於這個字符串可以在任何地方線出現,我們並不需要啓動的字符串的^錨。

取反的字符類[^.]匹配任何字符,但字面點(不需要在字符類內部轉義)。

所以,整個正則表達式的意思是:

  • [^.] - 任何字符,但文字點
  • \< - 開始單詞邊界(注意VIM風格的正則表達式)
  • [A-Z] - 1英文大寫字母
  • [a-z] - 1英文小寫字母
  • \w\+ - 1個或更多字母數字字符(注意VIM-style逃脫量詞:

\+      匹配1個或多個前面的字符...

UPDATE

按@ lcd047的評論,你可以使用\zs作爲一個向後看的替代品:

/[^.]\zs\<[A-Z][a-z]\w\+/ 

VIM Wiki

\zs          匹配任何位置,並設置匹配的開始位置:下一個字符是整個匹配的第一個字符。 ...

      /^\s*\zsif
匹配的 「如果」 在一個行的開始,忽略空白。
可以使用多次,使用匹配的 分支中遇到的最後一個。