Reputation: 1257
I've been working on a custom syntax highlighter for the Spike fuzzing API.
https://github.com/kkirsche/spike.vim
Very simple API, so it's a very simple file.
With this said, within strings, there are escape sequences such as \n for a new line, \r for a carriage return, as is common in many programming languages such as Python, C, etc. As these get interpreted differently, I want to highlight them in the same way you'd find for those programming languages.
My understanding is that these should be a match definition, but to be honest I'm not sure — and I don't know what type of character this is per Vim's different types (e.g. Comment, String, Special, Function, etc.)
What is the proper way to handle highlighting escape sequences such as these within a VIM syntax highlighting file?
Upvotes: 1
Views: 1311
Reputation: 172768
Looking at some syntax scripts that ship with Vim, all seem to (mostly) agree to link this to the SpecialChar
default highlighting group (which itself is linked to Special
by default):
$VIMRUNTIME/syntax/c.vim
:syn match cSpecial display contained "\\\(x\x\+\|\o\{1,3}\|.\|$\)"
syn region cString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend
hi def link cSpecial SpecialChar
$VIMRUNTIME/syntax/java.vim
:syn match javaSpecialChar contained "\\\([4-9]\d\|[0-3]\d\d\|[\"\\'ntbrf]\|u\x\{4\}\)"
hi def link javaSpecialChar SpecialChar
$VIMRUNTIME/syntax/javascript.vim
:syn match javaScriptSpecial "\\\d\d\d\|\\."
syn match javaScriptSpecialCharacter "'\\.'"
hi def link javaScriptSpecial Special
hi def link javaScriptSpecialCharacter javaScriptSpecial
The :help group-name
agrees with that:
*Special any special symbol SpecialChar special character in a constant Tag you can use CTRL-] on this Delimiter character that needs attention SpecialComment special things inside a comment
Upvotes: 1