StanAngeloff / php.vim

An up-to-date Vim syntax for PHP (7.x supported)
477 stars 69 forks source link

Can't change namespace color showing as phpRegion #90

Closed ghost closed 4 years ago

ghost commented 5 years ago

I would first off like to thank you for this amazing plugin.

My problem is I can't style the namespace at the top as it's showing as phpRegion that goes for the \and ;too

phpRegion

I would like it to match the use statements below and if possible style the ; a different color too.

How do I go about this?

StanAngeloff commented 5 years ago

Try adding a syntax extension:

function! PhpSyntaxOverride()
  syn keyword phpInclude namespace contained nextgroup=phpUseClass skipwhite skipempty
endfunction

augroup phpSyntaxOverride
  autocmd!
  autocmd FileType php call PhpSyntaxOverride()
augroup END

Does this work for you?

ghost commented 5 years ago

Hi @StanAngeloff thanks for getting back to me.

Sorry it was a bit late when I posted my comment so I don't think I was as descriptive as I should have been.

The code you posted hasn't had any effect on the color and they're still showing as phpRegion

I would like to change App\Http\Controllers\Authto yellow and color the separators the same color as the use statements below and if possible also change the semicolon color as they are all showing as phpRegion

StanAngeloff commented 5 years ago

Very odd, I was able to pop the snippet above in my .vimrc and the namespace … statement was coloured the same a the use … lines. I'll have a think on possible workarounds.

ghost commented 5 years ago

@StanAngeloff I just tested it with a different theme as I heavily modified it last night.

Now I able to get get the text color to match thank you.

My only problem is now is the separator for the namespace doesn't match the ones below and the semicolon is taking on the same color.

How do I style the \ and ; independently.

separatorandsemicolon

Thank you for taking the time to help me I appreciate it.

StanAngeloff commented 5 years ago

Can you pop this in your .vimrc:

" Synstack {{{

" Show the stack of syntax highlighting classes affecting whatever is under the cursor.
function! SynStack()
  echo join(map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")'), " > ")
endfunc

nnoremap <F7> :call SynStack()<CR>

" }}}

then restart and press <F7> over the \ inside the namespace statement. For me this results in the following message: phpRegion > phpUseClass > phpUseNamespaceSeparator and the colour is picked up correctly.

As for colouring the ; at the end of the line, I don't think this is easily doable just for namespace and use statements, sorry.

ghost commented 5 years ago

@StanAngeloff just tested with your function and it's still only showing phpRegion

What about changing the color of all php semicolons? I would be happy with that.

Thanks again for helping me debug this.

StanAngeloff commented 5 years ago

As for the semicolon, try adding:

syn match phpSemi /;/ contained containedin=phpRegion
hi phpSemi guifg=#ff0000 guibg=NONE gui=NONE

to your PhpSyntaxOverride() function. If you are using a terminal that doesn't support 24-bit colours, guifg won't have any effect, use ctermfg instead.

I'm out of ideas about the namespace thingie, I'm using stable Neovim which seems to honour the overrides.

StanAngeloff commented 5 years ago

BTW, have you upgraded php.vim recently? The namespace colouring was added as part of #31 which is a while ago, but if you haven't upgraded since, well…

ghost commented 5 years ago

It's working thank you very much. I'm confused though hoping you can explain what is happening as i'm new to vim.

I was editing my init.vim in NeoVim and apparently sourcing it was causing the problem, as I opened Sublime and did my editing there, closed iTerm and open it and it's working as expected, but as soon as I source my init.vim the coloring gets messed up again and goes away.

StanAngeloff commented 5 years ago

Sorry for the late reply, I misplaced GitHub's notification and only just realised there was a reply to this issue.

I was editing my init.vim in NeoVim and apparently sourcing it was causing the problem, as I opened Sublime and did my editing there, closed iTerm and open it and it's working as expected, but as soon as I source my init.vim the coloring gets messed up again and goes away.

I'm not sure what's going on to be fair. Is it possible you have two init.vim files, one getting sourced during start-up and the second one potentially clashing with it?