Can I make NotePad++ auto-replace a string?
-
Whenever I type “–” (two dashes), I’d like to make Notepad++ to replace them with an en-dash (–). Is this possible?
-
No, there is no built-in option for this.
Don’t know what is your use case. Just guessing - if you need en-dash often then just bind a key which insert en-dash.
It can be done e.g. with Autohotkey app, or in Notepad++ - e.g. with Pythonscript plugin. -
As @Mikhail-V suggests, you could do such a thing if you are willing to install and use the PythonScript plugin. Maybe there are other ways as well, but all would involve installing something extra, so why not the PS plugin? :-)
Here’s some quick sample PS code, modify/experiment/enhance as you like:
search_text = '--' replacement_text = 'en-dash' # <----- this is just placeholder, put what you want here def callback_sci_CHARADDED(args): if chr(args['ch']) == search_text[-1]: cp = editor.getCurrentPos() search_text_length = len(search_text) start_of_search_text_pos = cp - search_text_length if editor.getTextRange(start_of_search_text_pos, cp) == search_text: editor.beginUndoAction() editor.deleteRange(start_of_search_text_pos, search_text_length) editor.insertText(start_of_search_text_pos, replacement_text) editor.endUndoAction() end_of_search_text_pos = start_of_search_text_pos + len(replacement_text) editor.setCurrentPos(end_of_search_text_pos) editor.setSelection(end_of_search_text_pos, end_of_search_text_pos) editor.chooseCaretX() editor.callback(callback_sci_CHARADDED, [SCINTILLANOTIFICATION.CHARADDED])
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