Community
    • Login

    How to paste a selection in the same way as typing in overwrite mode?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 2 Posters 1.6k 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.
    • Mike de VogelM Offline
      Mike de Vogel
      last edited by

      As a programmer i sometimes have to replace certain pieces of a line, without the rest of the line indenting/unindenting.
      I am aware of the rectanglular selection and pasting etc, but i want to be able to paste my text OVER old text.
      See it as a “overwrite paste”.

      For example:
      FG,BG,BK,RD,GN

      At the spot of BG,BK (5 characters) i want to paste the text ASDAS (5 characters) to make:
      FG,ASDAS,RD,GN

      But if my selection was the text ASD (3 characters) it would have made:
      FG,ASDBK,RD,GN

      If my selection was the text ASDASDAS (9 characters) it would have made:
      FG,ASDASDAS,GN

      I want to do this WITHOUT first selecting the text, but just stand in front of the text and press CTRL+V;
      FG,(putting the cursor here and pressing CTRL+V)

      Is there a way to make this possible? It’s just like typing in overwrite mode but instead of typing i want to paste text over the old text.

      Seems like a simple idea i guess, maybe i’m missing something.

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA Offline
        Alan Kilborn @Mike de Vogel
        last edited by

        @Mike-de-Vogel

        If you are willing to use the Pythonscript plugin, it is relatively trivial to make something like this possible. Natively, however, I don’t believe Notepad++ can do such an overwrite paste.

        Mike de VogelM 1 Reply Last reply Reply Quote 1
        • Mike de VogelM Offline
          Mike de Vogel @Alan Kilborn
          last edited by

          @Alan-Kilborn That’s cool, i’ll be willing to use that if it’s possible that way!

          Can you help me with that?

          Thanks!

          Alan KilbornA 1 Reply Last reply Reply Quote 2
          • Alan KilbornA Offline
            Alan Kilborn @Mike de Vogel
            last edited by

            @Mike-de-Vogel

            Can you help me with that?

            Sure, here’s a first cut at a Pythonscript to do it:

            # -*- coding: utf-8 -*-
            
            from Npp import editor, notepad
            
            try:
                editor3h
            except NameError:
                editor3h = notepad.createScintilla()
            
            def clipboard_get_text():
                editor3h.setText('')
                editor3h.paste()
                paste_buffer_text = editor3h.getText()
                return editor3h.getText()
            
            def main():
                ct = clipboard_get_text()
                if len(ct) > 0:
                    cp = editor.getCurrentPos()
                    new_cp = cp + len(ct)
                    if new_cp > editor.getLength() - 1: new_cp = editor.getLength() - 1
                    if [ '\r\n', '\r', '\n' ][editor.getEOLMode()] == '\r\n':
                        print('got here a')
                        if new_cp < editor.getLength() - 1:
                            print('->', editor.getCharAt(new_cp))
                            if editor.getCharAt(new_cp) == 10: new_cp -= 1  # don't insert BETWEEN a \r\n pair
                    editor.setSelection(cp, new_cp)
                    editor.replaceSel(ct)
            
            main()
            

            To obtain and use Pythonscript (perhaps the most difficult part of all this), there are some guides at the following locations.

            If you use “installed” Notepad++, see:

            • https://github.com/notepad-plus-plus/notepad-plus-plus/issues/5394
            • https://community.notepad-plus-plus.org/topic/17256/guide-how-to-install-the-pythonscript-plugin-on-notepad-7-6-3-7-6-4-and-above

            If you use “portable” Notepad++, see:

            • https://community.notepad-plus-plus.org/topic/16942/pythonscript-any-ready-pyscript-to-replace-one-huge-set-of-regex-phrases-with-others/11
            Alan KilbornA 1 Reply Last reply Reply Quote 2
            • Alan KilbornA Offline
              Alan Kilborn @Alan Kilborn
              last edited by

              @Alan-Kilborn said in How to paste a selection in the same way as typing in overwrite mode?:

              print(‘got here a’)

              Oops; delete that line! Just for debugging! :-)

              1 Reply Last reply Reply Quote 1
              • Alan KilbornA Alan Kilborn referenced this topic on

              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