• Login
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.1k 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.
  • M
    Mike de Vogel
    last edited by Jan 5, 2020, 7:30 PM

    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.

    A 1 Reply Last reply Jan 5, 2020, 7:40 PM Reply Quote 0
    • A
      Alan Kilborn @Mike de Vogel
      last edited by Jan 5, 2020, 7:40 PM

      @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.

      M 1 Reply Last reply Jan 5, 2020, 7:46 PM Reply Quote 1
      • M
        Mike de Vogel @Alan Kilborn
        last edited by Jan 5, 2020, 7:46 PM

        @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!

        A 1 Reply Last reply Jan 5, 2020, 9:06 PM Reply Quote 2
        • A
          Alan Kilborn @Mike de Vogel
          last edited by Jan 5, 2020, 9:06 PM

          @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
          A 1 Reply Last reply Jan 6, 2020, 1:43 AM Reply Quote 2
          • A
            Alan Kilborn @Alan Kilborn
            last edited by Jan 6, 2020, 1:43 AM

            @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
            • A Alan Kilborn referenced this topic on Nov 11, 2021, 12:24 PM
            3 out of 5
            • First post
              3/5
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors