Skip to content

Commit 7959279

Browse files
bk2204da-x
authored andcommitted
Create highlight group for string delimiters
Some users wish to highlight string delimiters (e.g., quotation marks) in a different color from the body of the string itself. This feature is provided by several other languages' syntax highlighting rules, and is easy to achieve for Rust as well. Add a match group for the string delimiters and by default, assign it to the same highlight as the rest of the string, to preserve existing behavior. Users who wish to make use of this feature need only adjust their color scheme files to link the new rustStringDelimiter group to their preferred syntax highlighting group.
1 parent 4539a9a commit 7959279

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

syntax/rust.vim

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ syn match rustEscapeError display contained /\\./
144144
syn match rustEscape display contained /\\\([nrt0\\'"]\|x\x\{2}\)/
145145
syn match rustEscapeUnicode display contained /\\u{\%(\x_*\)\{1,6}}/
146146
syn match rustStringContinuation display contained /\\\n\s*/
147-
syn region rustString start=+b"+ skip=+\\\\\|\\"+ end=+"+ contains=rustEscape,rustEscapeError,rustStringContinuation
148-
syn region rustString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=rustEscape,rustEscapeUnicode,rustEscapeError,rustStringContinuation,@Spell
149-
syn region rustString start='b\?r\z(#*\)"' end='"\z1' contains=@Spell
147+
syn region rustString matchgroup=rustStringDelimiter start=+b"+ skip=+\\\\\|\\"+ end=+"+ contains=rustEscape,rustEscapeError,rustStringContinuation
148+
syn region rustString matchgroup=rustStringDelimiter start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=rustEscape,rustEscapeUnicode,rustEscapeError,rustStringContinuation,@Spell
149+
syn region rustString matchgroup=rustStringDelimiter start='b\?r\z(#*\)"' end='"\z1' contains=@Spell
150150

151151
" Match attributes with either arbitrary syntax or special highlighting for
152152
" derives. We still highlight strings and comments inside of the attribute.
@@ -286,6 +286,7 @@ hi def link rustEscapeUnicode rustEscape
286286
hi def link rustEscapeError Error
287287
hi def link rustStringContinuation Special
288288
hi def link rustString String
289+
hi def link rustStringDelimiter String
289290
hi def link rustCharacterInvalid Error
290291
hi def link rustCharacterInvalidUnicode rustCharacterInvalid
291292
hi def link rustCharacter Character

0 commit comments

Comments
 (0)