• Login
Community
  • Login

How to add, before every row with text, a new line with the same length but filled with spaces ?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 5 Posters 501 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.
  • F
    fabiospark
    last edited by fabiospark May 25, 2024, 6:45 PM May 25, 2024, 6:09 PM

    The title says it all.

    Imagine the lyrics of a song with no empty lines between the lines with text.
    I would like to add, before each line of text, a new line with the same length of the following line of text but filled with spaces.
    In this way, when I’ll start adding the chords symbols above each line of text I don’t have to type all the spaces between the chords and I could even activate the overwrite mode.

    I already know how to add empty lines but I can’t figure out how to read the length of an existing line and the rest.

    Thank you.

    C 1 Reply Last reply May 25, 2024, 6:45 PM Reply Quote 0
    • C
      Coises @fabiospark
      last edited by May 25, 2024, 6:45 PM

      @fabiospark said in How to add, before every row with text, a new line with the same length but filled with spaces ?:

      I would like to add, before each line of text, a new line with the same length of the following line of text but filled with spaces.

      First, pick a character that does not occur at the end of any line your text. I’ll use @ below.

      Next, use:
      Find what: (?-s)^.*?\S.*$
      Replace with: $&@\r\n$&
      to duplicate every line of text, with an @ at the end of the first copy.

      Now use:
      Find what: (?-s)\S(?=.*@$)
      Replace with: (a single space)
      to change all the characters on the @-lines to spaces, and finally:
      Find what: @$
      Replace with: (empty – delete the space!)
      to remove the @ signs.

      F 1 Reply Last reply May 25, 2024, 6:49 PM Reply Quote 3
      • F
        fabiospark @Coises
        last edited by fabiospark May 25, 2024, 6:55 PM May 25, 2024, 6:49 PM

        @Coises Thank you. That worked like a charm?

        Is there a direct way to turn the three single steps into a macro?

        Never mind, I recorded it.

        Thanks.
        fabio

        P A 2 Replies Last reply May 25, 2024, 6:55 PM Reply Quote 0
        • P
          PeterJones @fabiospark
          last edited by May 25, 2024, 6:55 PM

          @fabiospark said in How to add, before every row with text, a new line with the same length but filled with spaces ?:

          Is there a direct way to turn the three single steps into a macro?

          Start recording a macro, run those three regex, stop recording macro, save current macro.

          1 Reply Last reply Reply Quote 0
          • A
            Alan Kilborn @fabiospark
            last edited by Alan Kilborn May 25, 2024, 8:02 PM May 25, 2024, 8:02 PM

            @fabiospark

            You wouldn’t need anything special if you simply turn virtual spaces on; this allows your caret to move beyond line-endings. If you type a character while your caret is in virtual space, spaces will be added from the existing line-ending out to the column of the caret.

            1 Reply Last reply Reply Quote 1
            • G
              guy038
              last edited by guy038 May 26, 2024, 2:03 AM May 26, 2024, 2:02 AM

              Hello, @fabiospark, @coises, @Peterjones, @alan-kilborn and All,

              @coises, I suppose that the second and third regex S/R can be combined in a single one. So, first, we run :

              SEARCH (?-s).+

              REPLACE $0@\r\n$0

              Then, we execute :

              SEARCH (?-s).(?=.*@)|(@)

              REPLACE ?1:\x20


              An other possibility is to use the two successive regex S/R, below, which do not need any char to identify the lines to be filled with space characters :

              SEARCH (?-s).+\R

              REPLACE $0$0

              Then :

              SEARCH (?-s)(.)|\R.+\R

              REPLACE ?1\x20:$0


              If we suppose that we, first, select the blocks of lines needing modifications, here are the corresponding macros :

                      <Macro name="Duplicate lines with Spaces" Ctrl="no" Alt="no" Shift="no" Key="0">
                          <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                          <Action type="3" message="1601" wParam="0" lParam="0" sParam="(?-s).+" />
                          <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                          <Action type="3" message="1602" wParam="0" lParam="0" sParam="$0@\r\n$0" />
                          <Action type="3" message="1702" wParam="0" lParam="640" sParam="" />
                          <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                          <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                          <Action type="3" message="1601" wParam="0" lParam="0" sParam="(?-s).(?=.*@)|(@)" />
                          <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                          <Action type="3" message="1602" wParam="0" lParam="0" sParam="?1:\x20" />
                          <Action type="3" message="1702" wParam="0" lParam="640" sParam="" />
                          <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                      </Macro>
              

              Or :

                      <Macro name="Duplicate lines with Spaces Version 2" Ctrl="no" Alt="no" Shift="no" Key="0">
                          <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                          <Action type="3" message="1601" wParam="0" lParam="0" sParam="(?-s).+\R" />
                          <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                          <Action type="3" message="1602" wParam="0" lParam="0" sParam="$0$0" />
                          <Action type="3" message="1702" wParam="0" lParam="640" sParam="" />
                          <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                          <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                          <Action type="3" message="1601" wParam="0" lParam="0" sParam="(?-s)(.)|\R.+\R" />
                          <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                          <Action type="3" message="1602" wParam="0" lParam="0" sParam="?1\x20:$0" />
                          <Action type="3" message="1702" wParam="0" lParam="640" sParam="" />
                          <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                      </Macro>
              

              Best Regards,

              guy038

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