• Login
Community
  • Login

paste text to the right of cursor

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
11 Posts 3 Posters 3.0k 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
    fahrrad13
    last edited by Oct 6, 2020, 8:34 AM

    Hey,

    is there anyway that I can paste text to the right of the current cursor position?
    Normally when you paste a text, the cursor moves to the end of the inserted text, however, I want the cursor to stay at the beginning.
    As shown below:

    This is an editor
    

    Standard:

    This is an awesome editor
                      ^ Cursor is here
    

    Desired:

    This is an awesome editor
               ^ Cursor is here
    

    Thanks,
    Alex

    E 1 Reply Last reply Oct 6, 2020, 10:20 AM Reply Quote 1
    • E
      Ekopalypse @fahrrad13
      last edited by Oct 6, 2020, 10:20 AM

      @fahrrad13

      Did you try to record a macro?

      A 1 Reply Last reply Oct 6, 2020, 12:30 PM Reply Quote 0
      • A
        Alan Kilborn @Ekopalypse
        last edited by Oct 6, 2020, 12:30 PM

        @Ekopalypse

        I don’t see how this could be done as a macro, but it would be great if I could be enlightened! :-)

        A simple bit of Pythonscript seems to satisfy, though:

        p = editor.getCurrentPos()
        editor.paste()
        editor.setEmptySelection(p)
        
        E F 3 Replies Last reply Oct 6, 2020, 12:41 PM Reply Quote 4
        • E
          Ekopalypse @Alan Kilborn
          last edited by Oct 6, 2020, 12:41 PM

          @Alan-Kilborn

          to be honest, I don’t use macros - just thought it was possible.
          And it shouldn’t be that hard for the OP to test whether it is possible or not.

          A 1 Reply Last reply Oct 6, 2020, 12:44 PM Reply Quote 0
          • A
            Alan Kilborn @Ekopalypse
            last edited by Alan Kilborn Oct 6, 2020, 12:44 PM Oct 6, 2020, 12:44 PM

            @Ekopalypse said in paste text to the right of cursor:

            And it shouldn’t be that hard for the OP to test whether it is possible or not.

            The “stopper” for me in thinking about recording a macro for it is what to do after the paste. Sure I could cursor left 7 times, but this only handles the specific case of the paste data being 7 characters, not the generic case where data could be any width at all (the script handles that aspect of it just fine).

            E 1 Reply Last reply Oct 6, 2020, 12:47 PM Reply Quote 3
            • E
              Ekopalypse @Alan Kilborn
              last edited by Oct 6, 2020, 12:47 PM

              @Alan-Kilborn

              I was thinking about using CTRL+LEFT_ARROW but I guess I understand what you mean.
              The text could be more text to insert and not only one word I see.
              Right - macro seems not be the right choice here.

              1 Reply Last reply Reply Quote 3
              • F
                fahrrad13 @Alan Kilborn
                last edited by Oct 19, 2020, 9:30 AM

                @Alan-Kilborn
                Thanks for your help, that little python snippet works perfectly!

                1 Reply Last reply Reply Quote 0
                • F
                  fahrrad13 @Alan Kilborn
                  last edited by Oct 19, 2020, 11:15 AM

                  @Alan-Kilborn
                  Actually, now that I’m using it, I realised that its not perfectly working.
                  So I managed to use a python snippet and npp shortcut to paste text to the right, but when I (directly) go with the arrow key down to the next line, the cursor jumps to the end of the line/to the position of the end of the pasted text.
                  If I first use left right arrow, npp keeps the right position. Seems like npp doesnt update the cursor position properly.
                  Any idea how to fix this?
                  Thanks for your help!

                  E A 2 Replies Last reply Oct 19, 2020, 11:45 AM Reply Quote 0
                  • E
                    Ekopalypse @fahrrad13
                    last edited by Oct 19, 2020, 11:45 AM

                    @fahrrad13

                    One solution might be to add

                    editor.charRight()
                    editor.charLeft()
                    

                    to the end of the script.

                    1 Reply Last reply Reply Quote 1
                    • A
                      Alan Kilborn @fahrrad13
                      last edited by Oct 19, 2020, 11:58 AM

                      @fahrrad13 said:

                      but when I (directly) go with the arrow key down to the next line, the cursor jumps to the end of the line/to the position of the end of the pasted text.

                      Put this at the end of the prior script to fix that problem:

                      editor.chooseCaretX()

                      F 1 Reply Last reply Oct 24, 2020, 10:50 PM Reply Quote 3
                      • F
                        fahrrad13 @Alan Kilborn
                        last edited by Oct 24, 2020, 10:50 PM

                        @Alan-Kilborn thanks a lot - that works perfectly.
                        So here the final solution to this thread summarized from above:

                        p = editor.getCurrentPos()
                        editor.paste()
                        editor.setEmptySelection(p)
                        editor.chooseCaretX()
                        
                        1 Reply Last reply Reply Quote 3
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors