Skip to content

Instantly share code, notes, and snippets.

@phelipetls
Last active December 4, 2024 21:36

Revisions

  1. phelipetls revised this gist Sep 22, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions fstrings.vim
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    " ~/.vim/after/syntax/python.vim or ~/.config/nvim/after/syntax/python.vim
    syn match pythonEscape +{{+ contained containedin=pythonfString,pythonfDocstring
    syn match pythonEscape +}}+ contained containedin=pythonfString,pythonfDocstring

  2. phelipetls revised this gist Mar 25, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions fstrings.vim
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,7 @@ syn region pythonInterpolation contained

    syn match pythonStringModifier /:\(.[<^=>]\)\?[-+ ]\?#\?0\?[0-9]*[_,]\?\(\.[0-9]*\)\?[bcdeEfFgGnosxX%]\?/ contained containedin=pythonInterpolation
    syn match pythonStringModifier /![sra]/ contained containedin=pythonInterpolation
    syn match pythonStringModifier /\zs *= *\ze[}:!]/ contained containedin=pythonInterpolation

    hi link pythonfString String
    hi link pythonfDocstring String
  3. phelipetls revised this gist Oct 30, 2020. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion fstrings.vim
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    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
    @@ -7,8 +10,12 @@ syn region pythonfDocstring matchgroup=pythonQuotes

    syn region pythonInterpolation contained
    \ matchgroup=SpecialChar
    \ start=/{/ end=/}/
    \ 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
  4. phelipetls created this gist Oct 30, 2020.
    14 changes: 14 additions & 0 deletions fstrings.vim
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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=/}/
    \ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue,pythonDoctest

    hi link pythonfString String
    hi link pythonfDocstring String