Community
    • Login

    How to highlight certain words by color?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 4 Posters 2.2k 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.
    • Сергей КопышевС
      Сергей Копышев
      last edited by

      I’m from Russia, do not swear for my knowledge of English :3
      I want to highlight some words in color in the .yml file

      This picture will explain everything.

      Claudia FrankC 1 Reply Last reply Reply Quote 1
      • AZJIO AZJIOA
        AZJIO AZJIO
        last edited by

        спроси на форумер рубоард в теме Notepad++

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

          @Сергей-Копышев ,

          Doing it manually, you could highlight all the first-level keys, then Search > Mark All > Using First Style; then highlight all the second-level keys, and mark all using second style, etc… but I bet you want it more automated than that. (it’s hard to say, because a picture, though helpful, does not explain everything). Using these numbered styles, you would be limited to 5 different stylings.

          I know you can use the Mark menu (Search > Mark...) and a regex to match some groups of those… but I think that makes a “bookmark”, not a “styled mark”. I don’t know how to convert that “bookmark” into one of the “styled marks”. (I have never used the Mark or Bookmark features, except when answering questions on these forums, and that only rarely. I think @guy038 and/or @Claudia-Frank know a lot more about the marking features than I do.)

          For example, given text similar to what you showed, I was able to use the following regular expressions in Find what to select the first- or second- or third-level keys (I don’t know the YAML terminology for the “key” of a key: value pair – though the wikipedia:YAML article seems to imply that it’s key: value, which is common terminology for hashes; so I’ll stick with that. You might think of it as a “name” or a “label” or something else, too.)

          With options: ☑ Purge for each line, ☑ Regular Expression

          • level-1 key regex = ^\w+(?=:)
            • ^ = beginning of line,
            • \w+ = one or more word characters (alphanumeric or underscore _); no spaces allowed
            • (?=:) = make sure the word characters are followed by the literal colon, but don’t include the colon in the marking (this is pretty advanced: it’s called a look-ahead)
            • => this marks the “EXEC” from your image
          • level-2 key regex = ^ \K\w+(?=:)
            • ^ \K = beginning of line, with two literal spaces. The \K “throws away” everything before, so the spaces won’t be part of the text that’s marked
            • \w+ = same as before
            • (?=:) = same as before
            • => this marks “Scan_2”
          • level-3 key regex = ^ \K\w+(?=:) marked), then match one or more word characters and the colon)
            • ^ \K = beginning of line, with four literal spaces.
            • everything else is the same as before
          • all the %blah% text: %[^%]+%
            • % = literal percent
            • [^%]+ = one or more characters that aren’t a literal %
            • % = literal percent
            • if, instead, you want it limited to “word characters”, with no spaces or fancy characters, between the percents: %\w+%

          FYI: Please study some of the links found in FAQ DESK: Where To Find RegEx Docs to learn more about regular expressions.

          If you want to be able to automatically convert the bookmarked lines to specific Mark style-numbers, Guy or Claudia might chime in. It would probably involve automation using PythonScript or LuaScript if @Claudia-Frank answers; @guy038 might be able to do it solely with regular expressions, though even he might resort to scripting.

          1 Reply Last reply Reply Quote 2
          • Claudia FrankC
            Claudia Frank @Сергей Копышев
            last edited by

            @Сергей-Копышев

            see here what could be done.

            Cheers
            Claudia

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