Community
    • Login

    how to highlight the text between [] ?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 3 Posters 3.6k Views 2 Watching
    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.
    • Eduardo PerezE Offline
      Eduardo Perez
      last edited by

      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.

      Mark OlsonM PeterJonesP 2 Replies Last reply Reply Quote 0
      • Mark OlsonM Offline
        Mark Olson @Eduardo Perez
        last edited by Mark Olson

        @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

        Eduardo PerezE 1 Reply Last reply Reply Quote 1
        • PeterJonesP Offline
          PeterJones @Eduardo Perez
          last edited by PeterJones

          @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
          • Eduardo PerezE Offline
            Eduardo Perez @Mark Olson
            last edited by Eduardo Perez

            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

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors