I'm trying to add additional syntax highlighting to a plugin I'm using for syntax highlighting. I've tried adding the additional syntax file fstrings.vim
to the ~/.config/nvim/after/syntax
folder but my nvim is not picking it up.
Things I've tried:
- Check if
~/.config/nvim/after
and/or~/.config/nvim/after/syntax
is added to my runtime path.
- Only
~/.config/nvim/after
is added to my path - checked with:set rtp
>>runtimepath=~...,...,~/.config/nvim/after
- however I don't see the file loaded in:scriptnames
. How can I get the file to load?
- Change location of the file to
~/.config/nvim/after
instead of~/.config/nvim/after/syntax
- This does not work either.
- Manually load the file.
- This actually does work surprisingly. I can manually change the syntax of the file using
:set syntax=fstrings
however, all the original syntax highlighting provided by the plugin disappears, and only the highlighting provided (see the print statement in the image below) by thefstrings.vim
is used. This leads me to believe the path is set up correctly however nvim does not want to load it during startup and/or ignores it because of the plugin being used.
I know the /after/
folder is used to apply settings after previous settings, rather than overwriting. I've already tried the solution here and here but I've not been able to make it work. Any help on how to debug this would be appreciated.
" ~/.config/nvim/after/syntax/fstrings.vim
syn match pythonEscape +{{+ contained containedin=pythonfString,pythonfDocstring
syn match pythonEscape +}}+ contained containedin=pythonfString,pythonfDocstring
syn region pythonfString matchgroup=pythonQuotes
\ start=+[fF]\@1<=\z(['"]\)+ end="\z1"
\ contains=@Spell,pythonEscape,pythonInterpolation
syn region pythonfDocstring matchgroup=pythonQuotes
\ start=+[fF]\@1<=\z('''\|"""\)+ end="\z1" keepend
\ contains=@Spell,pythonEscape,pythonSpaceError,pythonInterpolation,pythonDoctest
syn region pythonInterpolation contained
\ matchgroup=SpecialChar
\ start=+{{\@!+ end=+}}\@!+ skip=+{{+ keepend
\ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue,pythonDoctest
syn match pythonStringModifier /:\(.[<^=>]\)\?[-+ ]\?#\?0\?[0-9]*[_,]\?\(\.[0-9]*\)\?[bcdeEfFgGnosxX%]\?/ contained containedin=pythonInterpolation
syn match pythonStringModifier /![sra]/ contained containedin=pythonInterpolation
hi link pythonfString String
hi link pythonfDocstring String
hi link pythonStringModifier PreProc
filetype
detected as'python'
(see:set ft?
on a Python file), so you should write your extended syntax rules in a file namedsyntax/python.vim
or perhapssyntax/python_fstrings.vim
(the file name can use_
as a separator, the first component matching the filetype name.) Does that seem to be what you're looking for? Let me know if that's the case and I'll turn this into an answer.set syntax=python_fstrings
all the syntax settings are overwritten except for the f strings ... just like before. So the file is being detected, just not loaded when a .py file is present.~/.config/nvim/after/syntax/python_fstrings.vim
and calledset syntax=python
and nothing changed within the file. I've looked into vim-polyglot which uses github.com/vim-python/python-syntax as the python syntax. I'm more interested in understanding why I cannot manually add additional syntax. Having plugins is nice, but I'd like to know how everything works :) It might be the order of how everything is defined. How could I debug that?syntax/python.vim
worked! Gah ... that was a whole round about. Thanks for all your help @filbranden!