When developing a vim plugin I'll publish soon, I want to highlight a text contained in a variable g:last_completion_text
.
Here below the code to
- define an highlight group named
PrompterCompletion
- assign the highlight to a text in a global vim variable
g:last_completion_text
:highlight PrompterCompletion ctermbg=3 ctermfg=0
:execute 'match PrompterCompletion /' . g:last_completion_text . '/'
If g:last_completion_text
is a single line the code works correctly.
echo g:last_completion_text
Hello! How can I assist you today?
But if g:last_completion_text
is a multiline text (contains newline), the match command fails.
echo g:last_completion_text
21. Regione dell'enogastronomia
22. Regione della neve
23. Regione delle malghe
24. Regione delle tradizioni contadine
25. Regione delle fiabe e delle leggende
26. Regione della natura incontaminata
27. Regione delle attività all'aria aperta
28. Regione dell'architettura alpina
29. Regione delle terme e del benessere
30. Regione della storia e della cultura tirolesi.
Screenshots
echo g:last_completion_text
echom g:last_completion_text
QUESTION:
Is there a way to let the match command accept newlines in the text contained in the referenced variable?
Is there a way to correct the command:
:execute 'match PrompterCompletion /' . g:last_completion_text . '/'
:help :match
. That command is mostly for users now; plugins should usematchadd()
or text properties.