Community
    • Login

    Move a block to the right or left

    Scheduled Pinned Locked Moved General Discussion
    3 Posts 2 Posters 15.8k Views 1 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.
    • Ramin ParsaR Offline
      Ramin Parsa
      last edited by

      Hi

      Are there shortcuts to Move a block to the right or left completely like microsoft word (ctrl+R and ctrl+L)

      ctrl+alt+R and ctrl+alt+L doesn’t work ( the following image)

      http://8pic.ir/images/0nu0oph3hj31aer7uidb.jpg

      I want to move all lines together on the left or right with a shortcut like microsoft word (like the following image)

      http://8pic.ir/images/dvprcoax4z2lrrkk98wl.jpg

      1 Reply Last reply Reply Quote 0
      • guy038G Online
        guy038
        last edited by guy038

        Hello, Ramin Parsa,

        It look easy and difficult, at the same time !!

        A) How to move a block of lines to the leftmost position ( so, at column 1 )? Quite easy, indeed !

        • Firstly, select your block of lines

        • Open the Replace dialog ( Ctrl + H )

        • SEARCH ^\h+

        • REPLACE EMPTY

        • Select the Regular expression search mode

        • Check the In selection option

        • Click on the Replace All button

        Et voilà !

        For instance, from the original text, below :

                                 This is
                         a
            short and simple test
                              and I
                                           strongly hope that
                      everything will turn right, in the
                end !
        

        We’ll get the text below :

        This is
        a
        short and simple test
        and I
        strongly hope that
        everything will turn right, in the
        end !
        

        This S/R should be easily written, as a macro !


        B) How to move a block of lines to the rightmost position ? This task is more difficult and SHOULD, normally, be done by a script language, as the Python or Lua plugin

        Indeed, if we’re going to use regexes, we have to find out, first, the number M of characters of the longest line of your block, as I suppose that the rightmost location is located just after the last character of the longest line !

        In our example above, the longest line contains 53 characters => M = 53

        Remarks :

        • I suppose that your text does NOT contain any tabulation character, only space characters !

        • To easily see the changes, in N++, just display the EOL characters ( View > Show symbol > Show all characters )

        • To run the three S/R, below, use, exclusively, the Replace All button !

        So, from our original text ,below :

                                 This is
                         a
            short and simple test
                              and I
                                           strongly hope that
                      everything will turn right, in the
                end !
        

        We perform a first S/R, which adds 53 spaces, at the end of all the lines of the block

        SEARCH $

        REPLACE 53 spaces

        We get the text below :

                                 This is                                                     
                         a                                                     
            short and simple test                                                     
                              and I                                                     
                                           strongly hope that                                                     
                      everything will turn right, in the                                                     
                end !                                                     
        

        Then, we run a second S/R, which delete any range of extra spaces, beginning at column 54, in all lines of the block

        SEARCH ^.{53}\K +

        REPLACE EMPTY

        This time, the text becomes, as below :

                                 This is                     
                         a                                   
            short and simple test                            
                              and I                          
                                           strongly hope that
                      everything will turn right, in the     
                end !                                        
        

        Finally, use the third and last S/R, below, which swap the final range of space characters with the first part of each line of the block :

        SEARCH ^(.+?)( +)$

        REPLACE \2\1

                                                      This is
                                                            a
                                        short and simple test
                                                        and I
                                           strongly hope that
                           everything will turn right, in the
                                                        end !
        

        No doubt that everyone understands, at once, why a macro, with the three successive S/R, would not adapted to that task :-((

        Of course, if the macro mechanism allow us to enter the value of the parameter M, we would just have to determine the longest line of the block and run the macro !

        Best Regards

        guy038

        Ramin ParsaR 1 Reply Last reply Reply Quote 0
        • Ramin ParsaR Offline
          Ramin Parsa @guy038
          last edited by

          @guy038

          It works

          Thank you very much

          1 Reply Last reply Reply Quote 0

          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