Reputation: 469
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:
but should look like this:
(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?
Upvotes: 3
Views: 2402
Reputation: 593
The plugin vim-python/python-syntax
has a broken syntax highlighting for f-strings, see https://github.com/vim-python/python-syntax/issues/98
But the fix (not complete yet) exists in vim repository: https://github.com/vim/vim/pull/14057
To try it now one can execute the following code:
mkdir -p "$HOME/.vim/syntax
curl -s https://raw.githubusercontent.com/vim/vim/21c6d8b5b6ef510c9c78b9dfb89a41146599505f/runtime/syntax/python.vim \
> "$HOME/.vim/syntax/python.vim"
After that, the f-strings are highlighted as a regular code
Upvotes: 0
Reputation: 469
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:
(with my color definitions)
Upvotes: 7