How to paste a selection in the same way as typing in overwrite mode?
-
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,GNAt the spot of BG,BK (5 characters) i want to paste the text ASDAS (5 characters) to make:
FG,ASDAS,RD,GNBut if my selection was the text ASD (3 characters) it would have made:
FG,ASDBK,RD,GNIf my selection was the text ASDASDAS (9 characters) it would have made:
FG,ASDASDAS,GNI 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.
-
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.
-
@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!
-
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:
-
@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! :-)
-
A 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