When using Vim the way my color syntax is now, when I type in $ it show开发者_运维技巧s yellow and when I write text it comes in white. How can I configure my vimrc to know when I am writing a PHP variable ($variable) and keep the color consistent between the $ and the words after it (variable in my example)? It is just a nuisance thing, but I hate seeing variable names with non-matching color, it drives me nuts.
You might want to consider getting this to fix your problem: http://www.vim.org/scripts/script.php?script_id=1571
There is another method for you ,if you want to display some custom color for some Class,methods, etc.
First of all, download the php.vim.
then, run the Highlight
test in Gvim
, you will get some keywords like this:
htmlTagN htmlTagN
htmlBoldUnderline htmlBoldUnderline htmlUnderlineBold
htmlBoldItalic htmlBoldItalic htmlItalicBold
htmlBold htmlBold
htmlBoldUnderlineItalic htmlBoldUnderlineItalic htmlBoldItalicUnderline htmlUnderlineBoldItalic htmlUnderlineItalicBold htmlItalicBoldUnderline htmlItalicUnderlineBold
htmlUnderlineItalic htmlUnderlineItalic htmlItalicUnderline
htmlUnderline htmlUnderline
htmlItalic htmlItalic
cssStyle cssStyle
javaScriptCommentSkip javaScriptCommentSkip
javaScriptParens javaScriptParens
javaScriptValue javaScriptValue javaScriptNumber
cssDefinition cssDefinition
cssAttributeSelector cssAttributeSelector
cssMediaBlock cssMediaBlock
cssFontDescriptorBlock cssFontDescriptorBlock
cssPseudoClass cssPseudoClass
cssSpecialCharQQ cssSpecialCharQQ
cssSpecialCharQ cssSpecialCharQ
cssLength cssLength
cssString cssString
phpRegion phpRegion
phpRegionAsp phpRegionAsp
phpRegionSc phpRegionSc
phpIdentifierComplex phpIdentifierComplex
phpMethodsVar phpMethodsVar
phpLabel phpLabel
phpFoldTry phpFoldTry
phpFoldCatch phpFoldCatch
NONE NONE
phpStructureHere phpStructureHere
phpMemberHere phpMemberHere
phpMethodHere phpMethodHere
phpPropertyHere phpPropertyHere
phpTernaryRegion phpTernaryRegion
phpHereDoc phpHereDoc
phpSpecialCharfold phpSpecialCharfold
phpPropertyInString phpPropertyInString
phpIdentifierInString phpIdentifierInString
phpIdentifierInStringComplex phpIdentifierInStringComplex
phpIdentifierInStringErratic phpIdentifierInStringErratic
phpErraticBracketRegion phpErraticBracketRegion
phpStaticUsage phpStaticUsage
phpStaticAccess phpStaticAccess
phpStaticVariable phpStaticVariable
phpStaticCall phpStaticCall
phpForeachRegion phpForeachRegion
phpForRegion phpForRegion
phpConstructRegion phpConstructRegion
phpSwitchConstructRegion phpSwitchConstructRegion
phpDoBlock phpDoBlock
phpSwitchBlock phpSwitchBlock
phpDoWhileConstructRegion phpDoWhileConstructRegion
phpStatementRegion phpStatementRegion
phpCaseRegion phpCaseRegion
phpArrayRegion phpArrayRegion
phpArrayRegionSimple phpArrayRegionSimple
phpArrayComma phpArrayComma phpListComma phpPREGArrayComma
phpListRegion phpListRegion
phpBlockRegion phpBlockRegion
phpParentRegion phpParentRegion
phpBracketRegion phpBracketRegion
phpFoldFunction phpFoldFunction
phpFoldClass phpFoldClass
phpFoldInterface phpFoldInterface
htmlRegion htmlRegion
phpDefineClassName phpDefineClassName
phpDefineClassImplementsName phpDefineClassImplementsName
phpDefineClassImplementsComma phpDefineClassImplementsComma
phpDefineClassImplementsCommentOneLine phpDefineClassImplementsCommentOneLine
phpClassBlock phpClassBlock
phpDefineClassBlockCommentOneline phpDefineClassBlockCommentOneline
phpDefineInterfaceName phpDefineInterfaceName
phpDefineFuncName phpDefineFuncName
phpDefineFuncProto phpDefineFuncProto
phpProtoArray phpProtoArray
phpDefineFuncBlockCommentOneline phpDefineFuncBlockCommentOneline
phpFuncBlock phpFuncBlock
phpDefineMethodName phpDefineMethodName
phpTryBlock phpTryBlock
phpCatchRegion phpCatchRegion
phpCatchBlock phpCatchBlock
phpFoldHtmlInside phpFoldHtmlInside
phpEchoRegion phpEchoRegion
phpClassStart phpClassStart
phpSyncStartOfFile phpSyncStartOfFile
phpSyncComment phpSyncComment
phpSyncString phpSyncString
phpRegionSync phpRegionSync
pregConcat pregConcat
pregClassEscapeMainQuote pregClassEscapeMainQuote
pregClassEscapeDouble2 pregClassEscapeDouble2
pregEscapeMainQuote pregEscapeMainQuote
phpPREGRegion phpPREGRegion
phpPREGOpenParentMulti phpPREGOpenParentMulti
phpPREGRegionMulti phpPREGRegionMulti
phpPREGStringStarter phpPREGStringStarter
phpPREGArrayRegion phpPREGArrayRegion
phpPREGArrayOpenParent phpPREGArrayOpenParent
pregNonSpecialEscape pregNonSpecialEscape
,here it is, your can modify the keywords for your php file, add some configure in your vimrc
like this:
hi TabLine guifg=#1C1D1F guibg=#BFBFBF gui=NONE
the 'TabLine
' can replace by the keywords. guifg
is the fore-color
, guibg
is the background color,gui
is the terminal color. you can configure it by yourself.
I believe what you're looking for is:
hi link phpIdentifier phpVarSelector
You can simply add this to your ~/.vimrc
file or you can create a php-specific "after" syntax file and add it there:
~/.vim/after/syntax/php.vim
Create the directories if they do not already exist.
For future highlighting changes you can use this mapping to figure out what the syntax group is under the cursor.
With this function in your .vimrc you can hit ctrl+p to show the syntactic group of the word/character under the cursor:
function! <SID>SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
nnoremap <C-p> :call <SID>SynStack()<CR>
With this sample PHP code:
$var_name = false;
if the cursor is on the $
I get:
['phpRegion', 'phpIdentifier', 'phpVarSelector']
else, if the cursor is on the n
of name
, I get:
['phpRegion', 'phpIdentifier']
which means that I need to set both phpIdentifier
and phpVarSelector
to the same color in my colorscheme to have a consistant look.
精彩评论