Community
    • Login

    SQL variable font color change

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 1.0k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Bogdan LinchukB
      Bogdan Linchuk
      last edited by

      Is there any way to change the color of variables in SQL (variable start with @)?

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Bogdan Linchuk
        last edited by PeterJones

        @Bogdan-Linchuk ,

        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:

        1. File > Open %AppData%\Notepad++\stylers.xml
          – if you are using a specific theme, rather than the default stylers.xml theme, you will have to edit the theme in your ...<install_directory>...\themes\ThemeName.xml
        2. Go to the <LexerType name="sql" section
        3. Add a new line after <WordsStyle name="Q OPERATOR" ... /> :
          <WordsStyle name="IDENTIFIER" styleID="11" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
        4. Save
        5. Exit Notepad++ and Restart
        6. Now Settings > Style Configurator > SQL will have the IDENTIFIER line in the Style box, and you can set the color of identifiers
          81e3a63e-b0ec-46ce-b9ac-6684ac416d2d-image.png
          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++.

        1 Reply Last reply Reply Quote 4
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors