SQL variable font color change
-
Is there any way to change the color of variables in SQL (variable start with @)?
-
By default, no.
However, the underlying Lexilla library that Notepad++ uses for syntax highlighting does have some styles that Notepad++ doesn’t currently list in the Style Configurator, so with a small configuration change, I think you can get what you want.
Since I’m not an SQL user, I picked the first hit when I searched the internet for
SQL at-variable
that gave some example SQL code, and used that for testing:DECLARE @TestVariable AS VARCHAR(100) SET @TestVariable = 'One Planet One Life' PRINT @TestVariable
If I follow the “Editing Config Files” instructions from the User Manual, and edit stylers.xml as follows:
- File > Open
%AppData%\Notepad++\stylers.xml
– if you are using a specific theme, rather than the defaultstylers.xml
theme, you will have to edit the theme in your...<install_directory>...\themes\ThemeName.xml
- Go to the
<LexerType name="sql"
section - Add a new line after
<WordsStyle name="Q OPERATOR" ... />
:
<WordsStyle name="IDENTIFIER" styleID="11" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
- Save
- Exit Notepad++ and Restart
- Now Settings > Style Configurator > SQL will have the IDENTIFIER line in the Style box, and you can set the color of identifiers
It doesn’t change the color of the @ symbol itself, but it seems to correctly colorize the variable’s name, anyway.
If that’s not enough for you, then you could use the plugin EnhanceAnyLexer to define a regex like
@\w+\b
and define a foreground color for the whole@TestVariable
expression.The Lexilla lexers have added new styles over the years, but as Notepad++ has updated to the newest lexers, the developers don’t go in and read all of the lexers’ source code (there are upwards of 80 lexers that Notepad++ has active) to find out of any have added style categories, and so they don’t know that they should update stylers.xml or the themes\DefaultDarkTheme.xml to make those extra styles available to users (and the other themes virtually never get updated).
So, unless a power-user of a particular lexer goes looking through the source code of that lexer, figures out the right name/styleID pairing for any styles not available in Style Configurator, updates their copy of stylers.xml/DefaultDarkMode.xml, and then create an issue with the Notepad++ Developers to ask them to incorporate that updated definition, those new styles are not likely to ever get updated in the stylers.xml/DefaultDarkMode.xml that get distributed with Notepad++.
- File > Open