• Login
Community
  • Login

Shift Left, No Tabs

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
15 Posts 4 Posters 1.8k 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
    Fred
    last edited by Jan 14, 2023, 2:01 PM

    Is there any way to SHIFT TEXT LEFT on a line, right off the screen, out of the file? In other words, I want to wipe out the first six columns of every line in the file, so this is not a tabbing operation. Yes, I can do this manually via Alt-Shift, but is there a command sequence I can use for a generalized macro? Thanks!

    P 1 Reply Last reply Jan 14, 2023, 3:56 PM Reply Quote 0
    • P
      Paul Wormer @Fred
      last edited by Paul Wormer Jan 14, 2023, 3:56 PM Jan 14, 2023, 3:56 PM

      @Fred
      Hit ctrl-h
      Find what: ^.{6}
      Use Regular expression (radio button bottom left)
      Replace with: nothing (empty field)
      Click on Replace all.

      A 1 Reply Last reply Jan 14, 2023, 4:00 PM Reply Quote 0
      • A
        Alan Kilborn @Paul Wormer
        last edited by Alan Kilborn Jan 14, 2023, 4:09 PM Jan 14, 2023, 4:00 PM

        @Paul-Wormer

        ^.{6}

        NO!
        Did you try it?
        It won’t work, in fact it will delete most of the entire document!
        References:

        • https://github.com/notepad-plus-plus/notepad-plus-plus/issues/12695
        • https://github.com/notepad-plus-plus/notepad-plus-plus/issues/6194

        @Fred

        One way to achieve it:

        Find: (?-s)^.{6}(.*)
        Replace: ${1}
        Search mode: Regular expression

        This assumes that all lines are 6 characters or greater.

        P 1 Reply Last reply Jan 14, 2023, 4:20 PM Reply Quote 1
        • P
          Paul Wormer @Alan Kilborn
          last edited by Jan 14, 2023, 4:20 PM

          @Alan-Kilborn Sure I tried it and it erased only the first 6 columns. (I did not check the box . matches new lines).

          A P 2 Replies Last reply Jan 14, 2023, 4:27 PM Reply Quote 0
          • A
            Alan Kilborn @Paul Wormer
            last edited by Jan 14, 2023, 4:27 PM

            @Paul-Wormer said in Shift Left, No Tabs:

            Sure I tried it and it erased only the first 6 columns.

            I think you’d better try it again, as it is not correct; see the references I cited.

            (I did not check the box . matches new lines).

            That doesn’t change the incorrectness of it anyway.

            But if you are providing a solution, and you don’t use (?-s) or (?s) in your regular expression, and you don’t say the state of the . matches newline checkbox, your solution is incomplete.

            1 Reply Last reply Reply Quote 0
            • P
              Paul Wormer @Paul Wormer
              last edited by Paul Wormer Jan 14, 2023, 4:32 PM Jan 14, 2023, 4:32 PM

              @Paul-Wormer
              I used the numbers 1234567890 and duplicated them a number of times. Then only 7890 remained. After your comment I added also some letters: 1234567890abcd and duplicated them, now the first 12 on each line were discarded (only cd remaining). In other words, you are right and my test case was too simplistic.

              1 Reply Last reply Reply Quote 1
              • F
                Fred
                last edited by Jan 14, 2023, 4:58 PM

                Thank you Paul for your prompt reply, and especially Alan for your correct reply! Although I don’t “know” regular expressions beyond their intent, I have printed the cheat sheet and will study it to learn from your example. Regardless, I was able to record a macro in Notepad++ which does exactly what I need to do; so again, THANKS!

                PS: It seems like what I want to do should be built-in to Notepad++, but that’s a separate topic. I’m not sure how to request/recommend it, as this is my first post here.

                Fred

                A 1 Reply Last reply Jan 14, 2023, 5:57 PM Reply Quote 1
                • A
                  Alan Kilborn @Fred
                  last edited by Alan Kilborn Jan 14, 2023, 6:35 PM Jan 14, 2023, 5:57 PM

                  @Fred said in Shift Left, No Tabs:

                  I have printed the cheat sheet

                  If you want more in the way of info, see the FAQ entry HERE.

                  It seems like what I want to do should be built-in to Notepad++, but that’s a separate topic.

                  Yea…I don’t know… It isn’t really a common thing. Sure, I’ve seen people ask about it before, but not with real regularity.

                  I’m not sure how to request/recommend it

                  There’s another topic in the FAQ that tells you how, HERE.

                  1 Reply Last reply Reply Quote 1
                  • A
                    Alan Kilborn
                    last edited by Jan 14, 2023, 8:30 PM

                    Probably an issue was created by the OP (username mismatch, but the timing is coincidental): https://github.com/notepad-plus-plus/notepad-plus-plus/issues/12804

                    1 Reply Last reply Reply Quote 0
                    • G
                      guy038
                      last edited by guy038 Jan 17, 2023, 11:05 AM Jan 15, 2023, 11:58 AM

                      Hello, @fred, @paul-wormer, @alan-kilborn,

                      To solve the @fred problem, it would be necessary to have this additional and simple feature in the Edit > Line Operations section :

                      Delete First Character

                      And, may be, we could add the following one, too :

                      Delete Last Character

                      Of course :

                      • These new features should act ALSO on a stream selection

                      • These new features should be included in the Shortcut Mapper manager

                      • These new features should be recordable too

                      In this case, @fred would just assigned a shortcut to the Delete First Character action and would hit it six times to achieve his goal !


                      In the meanwhile, here are two simple macros which perform, approximately, these features. Just one limitation : these two macros work with a predefined stream selection ONLY !

                      • The Delete First Character macro deletes the first character of the selection, throughout all the lines selected

                      • The Delete Last Character macro deletes the last character of the selection, throughout all the lines selected

                              <Macro name="Delete First Character" 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="$1" />
                                  <Action type="3" message="1702" wParam="0" lParam="128" sParam="" />
                                  <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                              </Macro>
                              <Macro name="Delete Last Character" 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="$1" />
                                  <Action type="3" message="1702" wParam="0" lParam="128" sParam="" />
                                  <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                              </Macro>
                      

                      So :

                      • Stop any instance of N++

                      • Insert the XML text above in the <Macros>.............</Macros> node of your active shortcuts.xml file and valid the modifications

                      • Restart N++

                      • Click on the Macro > Modify Shortcut/Delete Macro... menu option

                      • Double-click on the Delete First Character macro

                      • Attribute a shortcut to this macro and valid

                      • Close the Shortcut Mapper with th ESC key

                      • Do a normal selection, from beginning of line, of a consecutive range of lines

                      • Hit this shortcut repeatedly x times to delete the x first characters of each line of current selection


                      Important :

                      • If no selection exist, these two macros do nothing, as EXPECTED

                      • Note that if you select, on purpose, a multi-lines range of characters, not beginning the first line and/or not ending the last line, these two macros will just delete characters within the stream selection ONLY !

                      • In case of a rectangular selection, these macros consider that there is a stream selection from the beginning of the rectangular selection, in the first line to the end of the rectangular selection, in the last line.

                      • And note that if a rectangular selection contains a block of complete lines, these macros act as it was a normal stream selection

                      Best Regards

                      guy038

                      A 3 Replies Last reply Jan 15, 2023, 12:11 PM Reply Quote 3
                      • A
                        Alan Kilborn @guy038
                        last edited by Jan 15, 2023, 12:11 PM

                        @guy038 said in Shift Left, No Tabs:

                        Click on the Macro > Modify Shortcut/Delete Macro… menu option
                        Double-click on the Delete First Character macro

                        Nice Tip! I didn’t know double-click did anything in such a situation.

                        1 Reply Last reply Reply Quote 0
                        • A
                          Alan Kilborn @guy038
                          last edited by Jan 15, 2023, 12:13 PM

                          @guy038 said in Shift Left, No Tabs:

                          Do a normal selection, from beginning of line, of a consecutive range of lines

                          I would suggest using the “left click in line number margin and drag up/down” technique here for easy selection of full-line data.

                          1 Reply Last reply Reply Quote 2
                          • A
                            Alan Kilborn @guy038
                            last edited by Jan 15, 2023, 12:15 PM

                            @guy038 said in Shift Left, No Tabs:

                            Hit this shortcut repeatedly to delete the x first characters of each line of current selection

                            Or, select Run a Macro Multiple Times… and then specify the exact number of characters you want to delete.

                            1 Reply Last reply Reply Quote 2
                            • A
                              Alan Kilborn
                              last edited by Jan 15, 2023, 12:18 PM

                              Guy,

                              Do you think people might have “trouble” with this, maybe thinking it isn’t working right, if they have tab character(s) at start of line, and, because tab characters visually appear as multiple spaces, could possibly lead to confusion?

                              (Just asking…it isn’t going to happen to me, because I know what’s what.)

                              1 Reply Last reply Reply Quote 1
                              • G
                                guy038
                                last edited by Jan 15, 2023, 12:47 PM

                                Hi, @alan-kilborn,

                                Yes…, you’re right about it, Alan ! But how to get a simple behaviour ? Note that the macro is about deleting the first character, regardless its type !

                                And, anyway, in your post https://community.notepad-plus-plus.org/post/83341, where you proposed the right regex method to delete the first 6 chars, they could be tabulation chars, as well ?

                                BR

                                guy038

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