Sublime Forum

Golang syntax highlighting bug


If you enter two open curly braces {{ inside a string literal, e.g.: “{{” or {{, it messes up the whole syntax highlighting until it sees a }}. However, this isn’t expected, e.g.:


compiles and runs in Go, without closing off “}}”. you can try escaping it with {{ which fixes the highlighting, but doesn’t compile because it’s not a valid escape character. My current solution is to just do:

fmt.Println("{{") // "}}" some comment explaining why I have this weird comment

Then, the syntax highlighting is only messed up for that line, and doesn’t affect other lines, and the code still compiles



you should probably report this on the issue tracker for which ever package you are using that provides syntax highlighting for Go code… the maintainers may not check the ST forum

1 Like


Thanks for the reply! How can I find out what package that is, I didn’t explicitly install any Go syntax package myself?



It looks like this behaviour is exhibited in the Go syntax that ships directly with Sublime (Here I’m using the Go syntax from 3208):


Screencastify can’t capture the hover popup so the gif can’t show it, but:

  • Initially the second line’s scope is source.go meta.interpolation.go string.quoted.double.go
  • Adding just a }} to the end of the line has no effect on the scope at all
  • Adding "}} changes the second line’s scope to source.go string.quoted.double.go (i.e. the interpolation is closed, but the string is still open)
  • Adding }}" changes the second line’s scope to source.go meta.interpolation.go (i.e. the string is closed but the interpolation is still open
  • Adding "}}" (whether inside a comment or not) changes the second line’s scope to source.go variable.other.go

As such, I think the correct place to log this would be in the Packages repo on GitHub (otherwise it will get lost on the forum).

1 Like


Sweet, I actually managed to kinda fix this for my use case by changing this line (501 in the image):

It used to just match: “{{”

It works by only going to the ‘interpolation’ scope if it looks ahead and sees that it will also leave that scope with an appropriate }}. This is clearly a hack, and is not something I’m considering pull requesting. I’m just not that familiar with syntax files and assume there is a clean way of fixing this.

Thanks for your advice, posted here:



You should probably change that to {{(?=[^"]*}}).



you’re right, thanks. in either case, both are hacks and I’m sure there’s a better way to do this somehow. hopefully they’ll address the bug report I added to their github repo