Navigation

    Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Can I make NotePad++ auto-replace a string?

    Help wanted · · · – – – · · ·
    3
    3
    1271
    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.
    • Henry Vistbacka
      Henry Vistbacka last edited by

      Whenever I type “–” (two dashes), I’d like to make Notepad++ to replace them with an en-dash (–). Is this possible?

      Scott Sumner 1 Reply Last reply Reply Quote 0
      • Mikhail V
        Mikhail V last edited by Mikhail V

        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.

        1 Reply Last reply Reply Quote 1
        • Scott Sumner
          Scott Sumner @Henry Vistbacka last edited by

          @Henry-Vistbacka

          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])
          
          1 Reply Last reply Reply Quote 2
          • First post
            Last post
          Copyright © 2014 NodeBB Forums | Contributors