• Login
Community
  • Login

how to highlight the text between [] ?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 3 Posters 1.4k 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.
  • E
    Eduardo Perez
    last edited by Dec 22, 2023, 12:54 AM

    Hello, I use notepat++ a lot to do translations and I usually need to put notes in square brackets and I was wondering if there is a way to automatically highlight the text between the square brackets in a different color?
    That would be extremely useful for me and my editors.

    M P 2 Replies Last reply Dec 22, 2023, 1:18 AM Reply Quote 0
    • M
      Mark Olson @Eduardo Perez
      last edited by Mark Olson Dec 22, 2023, 1:18 AM Dec 22, 2023, 1:18 AM

      @Eduardo-Perez
      What do you mean by highlight in a different color? If you mean apply formatting to the text in a way that persists after the document is closed, that is not something that Notepad++ can do (unless you’re working with HTML, which seems unlikely from your question). See FAQ (Notepad++ is a text editor, not a word processor) for an explanation of why this is so.

      If you want to highlight the text in a way that is purely visual and does not persist when the document is closed, you could just use the Mark form (Ctrl+M with default keybindings, select Purge after each search, enter the regex (?s)\\[.+?\\], and hit Mark all. This will visually mark all the text in square braces, as shown below.

      5ba3968c-260b-4e2b-b708-0dbe0c4b49d7-image.png

      E 1 Reply Last reply Dec 23, 2023, 3:15 AM Reply Quote 1
      • P
        PeterJones @Eduardo Perez
        last edited by PeterJones Dec 22, 2023, 3:37 AM Dec 22, 2023, 1:51 AM

        @Eduardo-Perez ,

        It sounds to me like you might benefit from syntax highlighting. I don’t know what kind of file you are editing – whether it’s a YAML or JSON or INI or XML or something that Notepad++ already syntax-highlights; or whether it’s a plain text file.

        If it’s a plain text file – and especially if it has a consistent file extension, or just a few, that all files of that type will end with – then you can define a User Defined Language (“UDL”) that can syntax highlight (that is, automatically add color while you’re editing the file … though, as Mark pointed out, the color is not saved in the file, and someone viewing the file in another application or in a copy of Notepad++ that doesn’t have your UDL won’t see the colors). But you could use Language > User Defined Language > Define Your Language to create a new UDL, define the file extension that will automatically be colored, then go to the Operators & Delimiters tab; in Delimiter 1 style, you can put [ in the Open: and ] in Close, then click Styler to define the foreground and background colors for your highlight.

        In my example screenshot below, I called the language EdPer, and set bracketed text as red foreground on yellow background; you should, of course, pick a more meaningful language name and more aesthetically pleasing colors.
        dc554e9d-bef8-452d-8a18-5be99aa78535-image.png

        If you are using an already-existing file type (which I doubt, but maybe), then I’d suggest using whatever syntax that language defines for comments, rather than [bracketed text]. But if you still want to use bracketed text as your comments even in a pre-defined language, then I would suggest installing the plugin EnhanceAnyLexer (using the Plugins > Plugins Admin interface). Then you would open your file, and use Plugins > EnhanceAnyLexer > Enhance current language, and in the section of the config file that opened when you did that, you would do 0xcccc00 = \\[.+\\] to highlight stuff between brackets as cyan (EnhanceAnyLexer will only affect foreground colors, not background colors)
        b9846f49-2b28-473e-bb11-a565f1dd49f4-image.png

        1 Reply Last reply Reply Quote 4
        • E
          Eduardo Perez @Mark Olson
          last edited by Eduardo Perez Dec 23, 2023, 3:16 AM Dec 23, 2023, 3:15 AM

          Mark-Olson Thanks for the answer, but I need it to last between sessions

          PeterJones Thank you very much, this is just what I needed, I will use a modified language for my workgroup

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