I'm using Gedit to write C++ code, and have applied my custom syntax colour scheme which works (and looks) great with the exception of the string type, which, for both my custom style and the various bundled styles, is the same colour as the rest of the text. I am able to access the xml files that contain the style settings and there is no setting for defining the colour of string. Does anyone know how I can do this?


Ok I've found the solution. It's not in the style file, but deeper into the Gedit infrastructure in the language definition file instead. These files are store in /usr/share/gtksourceview-2.0/language-specs/ and the file in question is cpp.lang. Look for the list enclosed called id = "keyword" and add to this list the entry <keyword>string</keyword>, save the file, and restart Gedit. Done.

  • 1
    The string class was added in C++ and does not exist in C, so you probably shouldn't add it to the C file. Also the reason that it wasn't highlighted specially is that, unlike int or char, it's not a keyword - just the name of a class. – sepp2k Oct 15 '10 at 15:03
  • I've taken your advice and moved the edit to cpp.lang instead and edited my response appropriately. I think this come down to personal taste, as string is indeed the name of a class, but the syntax is used in much the same way as other declarations, when I've posted code to Stack Overflow, string has been highlighted there, so like I said, personal preference. – user2405 Oct 15 '10 at 16:06
  • It's highlighted on stackoverflow because stackoverflow highlights all languages the same and in some languages string is a keyword. And I'm not saying you shouldn't highlight string (though I personally would find it inconsistent if string is highlighted, but e.g. vector is not) - I'm just explaining why gedit doesn't. – sepp2k Oct 15 '10 at 16:50
  • What if I don't have access to the .lang file? How do I extend the lang file to add more keywords? – Srikrishnan Mar 13 '18 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy