pythonvimsyntax

Vim syntax highlighting of a Python formatted string


I am using Vim 8.1 on Debian 11 Bullseye, but it does not work in the recent Vim 8.2 either.

I would like to syntax highlight a Python formatted string, which looks currently in vim so:

is

but should look like this:

should

(compare the curly braces and their content)

Does anyone know of a plugin that does this "properly", or can provide the syntax I need to insert in /usr/share/vim/vim81/syntax/python.vim to achieve this highlighting?


Solution

  • There is an appropriate highlighter on github: https://github.com/vim-python/python-syntax

    In .vimrc, you need to enable either everything with

    let g:python_highlight_all = 1
    

    or specifics, like I did:

    let g:python_highlight_string_format = 1
    let g:python_highlight_builtin_objs  = 1
    

    A python formatted string now looks like:

    enter image description here

    (with my color definitions)