Recursive Input to query-replace

The other day I needed to change all occurrences of a certain Unicode character with another in a large file. No problem, I thought, I’ll just fire off a query-replace and be done. Of course, now I had to enter those two Unicode characters to the query-replace prompt. My usual way of entering Unicode characters is with 【Ctrl+x 8】 but that didn’t work because I was already in the minibuffer. Grrrr.

After a moments thought I brought up the *scratch* buffer, put the two characters in it with my usual 【Ctrl+x 8】 procedure, loaded the characters into a couple of registers, and used the registers to give the characters to query-replace. Even granting that needing to do this is a rare occurrence, that was a singularly terrible solution.

In my shame, I started thinking of better ways to do it. The first thing I realized was that the registers were silly (I had just been using a register for something else and they were on my mind). Instead, I could have merely copied the two characters into the kill ring with 【Meta+w】 and then used 【Ctrl+y】 and 【Meta+y】 to give them to query-replace. Still not a good solution but better than the nonsense with registers.

Finally, I remembered my previous post on making the minibuffer recursive. When I wrote about that I set enable-recursive-minibuffers to t but because I didn’t use it in my day to day work I never added it to my init.el. Too bad. Once I re-enabled the recursive minibuffer processing I was able to do what I wanted in the first place: fire off query-replace and then enter the characters with 【Ctrl+x 8】. The very next thing I did was to add it to my init.el.

Again, entering Unicode characters in the minibuffer is not something I do very often but when I need it, this is a great solution. Does anyone know of a better solution?

This entry was posted in General and tagged . Bookmark the permalink.