Community
    • Login

    Multi-cursor editing

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    53 Posts 8 Posters 8.3k 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.
    • PeterJonesP
      PeterJones
      last edited by

      That is not a complicated regex to develop for search-and-replace. If I saw your video correctly, you want to search for some text, BEAMON; on the line after that, you want to add text (something like F200), and on the line after that, you want to add different text (F1000).

      • SEARCH = (?-s)^(BEAMON\R)^(.*)(\R)^(.*)$
        • (?-s) = turn off .-matches-newline inside the regex (override the GUI checkbox)
        • ^(BEAMON\R) = search for a line matching BEAMON with newline, store in group1 aka ${1}
        • ^(.*)(\R) = search for the entire next line and put in group2 aka ${2} and put the newline sequence in group3 aka ${3}
        • ^(.*)$ = search for the entire next line and put it in group4 aka ${4}
      • REPLACE = ${1}${2} F200${3}${4} F1000
        • build replacement from group 1, group 2, F200, group 3, group 4, and F1000
      • MODE = regular expression

      Start with a file like:

      BEAMON
      first
      second
      other
      ...
      BEAMON
      uno
      dos
      tres
      ...
      BEAMON
      eins
      zwei
      drei
      ...
      

      End with a file like

      BEAMON
      first F200
      second F1000
      other
      ...
      BEAMON
      uno F200
      dos F1000
      tres
      ...
      BEAMON
      eins F200
      zwei F1000
      drei
      ...
      

      With the details I gave, it should be customizeable to other similar replacements.

      So far, I have still seen nothing that indicates it needs more than regex search-and-replace.

      PeterJonesP 1 Reply Last reply Reply Quote 2
      • PeterJonesP
        PeterJones @PeterJones
        last edited by PeterJones

        @PeterJones said in Multi-cursor editing:

        That is not a complicated regex to develop

        Re-reading that statement some time later, I feel I should explain:

        I wasn’t try to say, “it’s easy, and you’re an idiot if you couldn’t figure it out” – not at all. Regex is a very powerful tool, and it’s hard to be an expert in it. I am far from an expert, and learn new regex thought processes and tactics from others of the regulars in this forum on a daily basis.

        What I meant was, “compared to some of the regexes I’ve seen, even in this forum, it’s not a complicated one with lots of conditionals and resets and assertions”.

        When I developed this regex for you, I basically said to myself: “the goal is to look for a particular word as the only component of a first line, then grab that and the next two lines into about three storage groups (one per line); in the replacement, use those groups, and put the F200 and F1000 at the end of the second and third lines”. I then translated those English phrases into the regex “phrases” I am comfortable with.

        While doing that translation from mental algorithm to regex syntax, I realized I needed to treat the newline that came after the second line separately from the rest of the second line (because I want to put something between the second line and its newline sequence); since I had to match it separately, I put it into a separate group, so that I wouldn’t have to guess whether your document used Windows or Linux newline sequences in the replacement; I also realized I don’t really need to do anything about the newline on the third line, so I don’t need to capture it at all (it has the side benefit of meaning that whether your file ends on the third line, or there’s a newline and another single or thousand or indeterminate lines after, it will work).

        The best way I find to develop a regex is to break down my requirements into simple chunks; if those chunks require nothing more than pattern matching and memory, it’s usually straightforward to translate into a regex. If those chunks use words like “add 5” or “add N” or “insert random number”, then I realize I need a full programming language rather than just regex.

        If you can express a problem in those terms, then even if you don’t know all the regex syntax to do it, usually a person with more regex experience can help you with that. And that’s what we often do here (even though regex are not the primary purpose for the existence of this forum). And if the regex I suggest doesn’t work exactly, show us a better example of the text, which includes more edge cases, and examples of things that should and shouldn’t change, and show us the before and after, and we can usually muddle through it – especially if you’re showing effort.

        ----

        Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as plain text using the </> toolbar button or manual Markdown syntax; screenshots can be pasted from the clipbpard to your post using Ctrl+V. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get… Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.

        1 Reply Last reply Reply Quote 0
        • czmaniakC
          czmaniak
          last edited by

          Regex is something new for me that I have no experience with, I do not know where to write text with commands, where to start? My English is not so good it can also be a bit of a problem. I’ll try to look at the forum content for more information.

          Thank you very much for your time and effort to explain this issue to me. I appreciate it really much

          Alan KilbornA EkopalypseE 2 Replies Last reply Reply Quote 0
          • Alan KilbornA
            Alan Kilborn @czmaniak
            last edited by

            After all the back and forth above, I’ve sort of changed my mind. I think that the way the OP wants to go about this is very reasonable, without using search-and-replace. The scenario is rather rare, but for where text is very regular before or after the original search is conducted…I can see it.

            1 Reply Last reply Reply Quote 0
            • EkopalypseE
              Ekopalypse @czmaniak
              last edited by

              @czmaniak

              If I understand this correctly, then one, non-plugin way would be,
              to press and hold the CTRL button and click with the mouse on the
              respective places.

              Alan KilbornA 1 Reply Last reply Reply Quote 1
              • Alan KilbornA
                Alan Kilborn @Ekopalypse
                last edited by

                @Ekopalypse said in Multi-cursor editing:

                If I understand this correctly, then one, non-plugin way would be,
                to press and hold the CTRL button and click with the mouse on the
                respective places.

                True, but I get the feeling we are talking about hundreds of such places, potentially, which makes that problematic.

                EkopalypseE 1 Reply Last reply Reply Quote 2
                • EkopalypseE
                  Ekopalypse @Alan Kilborn
                  last edited by

                  @Alan-Kilborn
                  I assume so too.
                  I do have a little PS script for selecting all same words

                  from Npp import editor
                  first_line = editor.getFirstVisibleLine()
                  editor.setTarget(0, editor.getTextLength())
                  editor.multipleSelectAddEach()
                  editor.rotateSelection()
                  editor.setFirstVisibleLine(first_line)
                  
                  1 Reply Last reply Reply Quote 2
                  • EkopalypseE
                    Ekopalypse
                    last edited by

                    In case someone is trying this.
                    If no word is selected the first execution would select the current word
                    and the next execution all others.

                    Alan KilbornA 1 Reply Last reply Reply Quote 0
                    • Alan KilbornA
                      Alan Kilborn @Ekopalypse
                      last edited by

                      @Ekopalypse

                      Yes, this (or a variant which included a search) would get all of the carets in the correct place, but from there the OP’s desire is to be able to move all of the carets in junction to a constants offset from that point, and which point insertion/deletion would commence. At least this is what I gather from watching the OP’s video. And if I try something like that after running your script, all but one of the carets is removed as soon as I do the first cursor movement operation. I expected this.

                      But I also respect the OP’s desire for something like this to be possible.

                      1 Reply Last reply Reply Quote 1
                      • astrosofistaA
                        astrosofista
                        last edited by

                        @Alan-Kilborn said in Multi-cursor editing:

                        Yes, this (or a variant which included a search) would get all of the carets in the correct place, but from there the OP’s desire is to be able to move all of the carets in junction to a constants offset from that point, and which point insertion/deletion would commence. At least this is what I gather from watching the OP’s video. And if I try something like that after running your script, all but one of the carets is removed as soon as I do the first cursor movement operation. I expected this.

                        Hi @Alan-Kilborn, @Ekopalypse, All:

                        As I understand, Ekopalypse’s script in conjunction with the BetterMultiSelection plugin provide an interesting approach if not an actual solution to OP’s request.

                        Take a look to how I can resolve the sample that Op posted before in this thread:

                        giphy

                        If needed, I can post the commands used to move the caret in the above embedded gif.

                        EkopalypseE 1 Reply Last reply Reply Quote 4
                        • EkopalypseE
                          Ekopalypse @astrosofista
                          last edited by

                          @Alan-Kilborn, @astrosofista

                          I watched the youtube video and it looks like you can do this
                          with my script.
                          You do get multiple selection and those will move when using the arrow keys.
                          What do I miss??

                          astrosofistaA 1 Reply Last reply Reply Quote 0
                          • astrosofistaA
                            astrosofista @Ekopalypse
                            last edited by

                            @Ekopalypse said in Multi-cursor editing:

                            You do get multiple selection and those will move when using the arrow keys.
                            What do I miss??

                            @Ekopalypse

                            You need to check the Multi-Selection option in Preferences and install the BetterMultiSelection plugin.

                            EkopalypseE 1 Reply Last reply Reply Quote 1
                            • EkopalypseE
                              Ekopalypse @astrosofista
                              last edited by

                              @astrosofista

                              thx, but I can already do what your gif shows without having BetterMultiSelection installed just by using my script.

                              Alan KilbornA astrosofistaA 2 Replies Last reply Reply Quote 1
                              • Alan KilbornA
                                Alan Kilborn @Ekopalypse
                                last edited by

                                @Ekopalypse

                                You do get multiple selection and those will move when using the arrow keys.

                                Well, I’ve never had much luck with doing that in a “real” way. A real way would be a real problem I’m working on.

                                BTW, I like futzing around with Notepad++ and its peculiarities, but it gets frustrating fast when you are trying to do something “real” and you run into Notepad++'s bugs. :-)

                                1 Reply Last reply Reply Quote 0
                                • EkopalypseE
                                  Ekopalypse
                                  last edited by

                                  this is how it looks like on my PC

                                  1 Reply Last reply Reply Quote 3
                                  • astrosofistaA
                                    astrosofista @Ekopalypse
                                    last edited by

                                    @Ekopalypse said in Multi-cursor editing:

                                    thx, but I can already do what your gif shows without having BetterMultiSelection installed just by using my script.

                                    @Ekopalypse

                                    You are right. I disabled the plugin and your script does all the work and OP should pay close attention to it.

                                    Anyway I still believe that the conjuntion of both the plugin and your script creates a better tool. The plugin works nice with contiguous selections, which it can create by draging, and your script extend its capabilities to make distant selections. I thank you for it.

                                    By the way, have you plans to make the plugin able to search for partial words? At first glance looks like a nice addition.

                                    Disclaimer: I am not related in any way with the mentioned plugin, just a happy user.

                                    EkopalypseE 1 Reply Last reply Reply Quote 2
                                    • EkopalypseE
                                      Ekopalypse @astrosofista
                                      last edited by

                                      @astrosofista said in Multi-cursor editing:

                                      Anyway I still believe that the conjuntion of both the plugin and your script creates a better tool.

                                      Can be the case absolutely, @dail does a great job with all of his plugins. :-)

                                      By the way, have you plans to make the plugin able to search for partial words? At first glance looks like a nice addition.

                                      Just select the part of the word you are interest in and it should respect it already. This is a scintilla feature not really my work.

                                      dailD astrosofistaA 2 Replies Last reply Reply Quote 3
                                      • dailD
                                        dail @Ekopalypse
                                        last edited by

                                        @Ekopalypse I use BetterMultiSelection in conjunction with LuaScript to select multiple instances and then edit them simultaneously…works quite nicely.

                                        EkopalypseE Michael VincentM 2 Replies Last reply Reply Quote 2
                                        • EkopalypseE
                                          Ekopalypse @dail
                                          last edited by

                                          @dail

                                          I have no doubt that this works great. :-)

                                          1 Reply Last reply Reply Quote 1
                                          • astrosofistaA
                                            astrosofista @Ekopalypse
                                            last edited by

                                            @Ekopalypse said in Multi-cursor editing:

                                            Just select the part of the word you are interest in and it should respect it already. This is a scintilla feature not really my work.

                                            Yes, it works fine… almost all the time. In one of my tests Notepad++ ceased to respond and have to quit it via the taskbar.

                                            Better stop for today.

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