Save "Find what" and "Replace with" in Notepad++



  • Is it possible in NPP++ to save characters in “Find what” and “Replace with” for late use?



  • E.g. I have a complex search criteira “[-·•…:_,~..\s]{3,}”, if NP++ can remember it, I don’t need to type it every time.

    This feature is available in Akelpad, it allow you to save your regular “searh and replace” string under a user defined name and call it when you need it.



  • @S-Y

    That functionality doesn’t exist currently in Notepad++, but I’ve seen it requested before, and I agree that it is a good idea.



  • I’d like to notice that N++ already saves the contents of the “Find what” and “Replace with” fields beteen different invocations of the Search/Find… dialog, but these contents are not persistent between multiple N++ invocations.

    If the history of these fields was persistent, then there would need to be some way to edit or at least clear this history, lest it would become very polluted over time.



  • @Robinson-George said:

    but these contents are not persistent between multiple N++ invocations

    They persist for me between runs of N++!

    way to edit or at least clear this history, lest it would become very polluted

    It only saves a limited number of entries, so the “pollution” is minimal. It is possible to change the amount of history retained.

    BTW, the OP didn’t actually say this, but I think the desire is to have the corresponding Find what and Replace With data paired together so that they could be recalled for re-use simultaneously at some later time. This currently in no way exists–the history for these fields is independent.



  • Just as a comment, with NppExec v0.6 beta 1 it’s already possible to specify something like the following:

    set local replaceFlags = NPE_SF_REPLACEALL | NPE_SF_INWHOLETEXT | NPE_SF_REGEXP
    sci_replace $(replaceFlags) "find what 1" "replace with 1"
    sci_replace $(replaceFlags) "find what 2" "replace with 2"
    ...
    


  • IIRC macro recording saves the specific search criteria, which should be in shortcuts.xml.



  • Yes, macro recording is the solution. I’m using it.
    Just fill the find and replace text boxes, and click macro recording, and click replace, and stop recording. And then, Macro -> Save Current Recorded Macro…
    You can specify a hot key for it.



  • I took the OP’s request to be one where you would do the saving and recalling of specific searches/replacements directly from the Find dialog. I’m not sure why I interpreted it that way now that I re-read the two postings by the OP…

    One of the downsides of macro-izing a search or a replacement is that it is difficult to tweak a lengthy search/replace expression that is already recorded and saved. Once it is saved as a macro, it is pretty much hardcoded/abstracted (unless you want to go to shortcuts.xml to get a copy of it).

    It seems to me that it would be nice if there were GUI elements in Notepad++ which would allow recalling (by user-given name) a previous search expression (or search+replace pair) and accompanying options, and then of course saving it back again, either to the same name or different.

    Prompting capability would be nice as well: A special sequence could be embedded in a search/replace expression which, when the search is run, would prompt the user (simple popup input box) to enter some data specific to the current search needs. That data would then be combined with the other parts of the setup and the search/replace executed. As it exists now, if you have many very similar search/replace needs, each has to be a separately-named macro.

    Maybe something in the macro-running process for this which would simply pull up the Find dialog and preset all the fields a certain way would be useful. Then the user could tweak the preconfiguration (or not) and execute.

    Just some ideas, which I’m sure have been discussed before… In short, it is great to be able to macro-ize a search/replacement…but IMO the facility could be enhanced.



  • Why not just save a user-defined dictionary of all your codes in any format you think is best.

    I use one where I save all my codes each accompanied with headers so i can find what I need easily, like:

    • 1 ⁣ ⁣ ⁣#Tags: beta,query,inventory,report,qoh,stock
      2 ⁣ ⁣ ⁣#Language: MySQL
      3 ⁣ ⁣ #Date: 3/26/18
      4 ⁣ ⁣ ⁣⁣#Code:
      5 ⁣ ⁣ ⁣[
      6 ⁣ ⁣ ⁣SELECT * FROM table
      7 ⁣ ⁣ ⁣]

    And if I was to add a search and replace code to this personal library…

    • ⁣ ⁣ ⁣8⁣ ⁣ ⁣ ⁣#Tags: search,find,replace,query
      ⁣ ⁣ ⁣9 ⁣ ⁣ ⁣#Language: Regular Expression
      10 ⁣ ⁣ #Date: 3/26/18
      11 ⁣ ⁣ #Code:
      12 ⁣ ⁣ [
      13 ⁣ ⁣ Search= [-·•…:_,~..\s]{3,}
      14 ⁣ ⁣ Replace= null
      15 ⁣ ⁣ ]

    You can be more detailed than that, but once you find out what works best for you, adding changes to your “Dictionary” or “Library” of codes can get really simple. You can define any keywords you want for the headers and whichever open/close characters separating the code blocks from each other. In my chicken scratch example,I can customize the language to either separate each block by the first bracket to the last bracket or the first hashtag to the last bracket. I’m not too sure about the code folding since I don’t really use that, but I would imagine that is possible.

    I also noticed that if you use a tag system like in my example, it would be very difficult to find what you need if you have thousands of code blocks with similar tags. And you can do a regexp find lines that contains all words, but that would just void the purpose of you having to type regular expressions every time. So like I said, you can be more detailed than my example, you can use a naming convention like “regex-find-name” where name is a word or phrase you’d give that function. You could also build your dictionary in a different format that makes searching for multiples words on the same line much easier. A bad recommendation would be excel, but that’s the simplest method I can think of. Write the dictionary in a csv format and run a saved formula to check if all words exist on the same row. But if you have the time, build yourself a small desktop tool with all these functions to build and search your dictionary. Create forms to add to it, search and modify or remove definitions. There’s gotta be a program for this already no!? A personal and highly customizable dictionary?


Log in to reply