Skip to content

Instantly share code, notes, and snippets.

@finite-state-machine
Forked from phelipetls/fstrings.vim
Last active March 18, 2022 09:39
Show Gist options
  • Save finite-state-machine/aa12c251fc4a7809d1484c4d82d9b064 to your computer and use it in GitHub Desktop.
Save finite-state-machine/aa12c251fc4a7809d1484c4d82d9b064 to your computer and use it in GitHub Desktop.
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
" highlight the '=' in e.g. f'{foo=}':
syn match pythonStringModifier /\zs *= *\ze[}:!]/ contained containedin=pythonInterpolation
hi link pythonfString String
hi link pythonfDocstring String
hi link pythonStringModifier PreProc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment