<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[ReplaceAll InSelection keeps selection...sometimes!]]></title><description><![CDATA[<p dir="auto">In attempting to record a macro to do 3 substitutions on a piece of selected text, I wanted to do it in one regex operation, but I hit a limitation (may go more into this later, because it is somewhat interesting…).</p>
<p dir="auto">So instead of one operation, I split it into more than one, but when I did that I discovered another something interesting.</p>
<p dir="auto">Here’s an example:</p>
<p dir="auto">Problem statement:  Replace (in-selection) all <code>foo</code> to <code>FOO</code>.  Then, Replace (in-selection) all <code>bar</code> to <code>BAR</code>.  Next, put <code>I am </code> onto the front of the selection.</p>
<p dir="auto">So, the macro (or the series of replacement actions) would take <code>foobar</code> and we’d end up with <code>I am FOOBAR</code>.  I am able to achieve this, luckily, but what I discovered makes me wonder if this “general technique” would fail with certain desired text transformation sequences.</p>
<p dir="auto">So we put “foobar” as text in a N++ tab, select it, and things look like this:</p>
<p dir="auto"><img src="/assets/uploads/files/1607957665987-6b0e3df8-7c57-49c6-acec-d7133bc961e9-image.png" alt="6b0e3df8-7c57-49c6-acec-d7133bc961e9-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Then we fire up the Replace box.  <em>In selection</em> is ticked so we just do a literal <em>Find what</em> of “foo” and a <em>Replace with</em> of “FOO”.  We press <em>Replace All</em> and we get:</p>
<p dir="auto"><img src="/assets/uploads/files/1607957713846-683285e3-7458-4283-9177-bbe81a5ae947-image.png" alt="683285e3-7458-4283-9177-bbe81a5ae947-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">“bar” -&gt; “BAR” as the next replacement is set up and proceeds similarly, to obtain:</p>
<p dir="auto"><img src="/assets/uploads/files/1607957745530-377cbf84-fdd0-4ab2-8571-6d58699554e4-image.png" alt="377cbf84-fdd0-4ab2-8571-6d58699554e4-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Oh! but wait! What happened to the selection itself?  It has now dropped the “BAR” part from the selection!?</p>
<p dir="auto">Keep on going, how to put "I am " on the front of this (remaining) selection?  What I thought of was regex replacing <code>(?-s).+</code> with the new text.  Indeed that works, and the resulting text is:</p>
<p dir="auto"><img src="/assets/uploads/files/1607958028688-e43a70dc-eddb-4640-9cef-8e1ee91c7dfb-image.png" alt="e43a70dc-eddb-4640-9cef-8e1ee91c7dfb-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Notice now that the “selection” has entirely vanished (and remember all replacement ops described above have been with <em>In selection</em> ticked), so…if I had just one more thing I wanted to do to “selected text” via a <em>Replace All</em>, I’d be out of luck.</p>
<p dir="auto">To add to the inconsistency, I still see <em>In selection</em> ticked in the <em>Replace</em> window, but as I just said, I have no currently selected text:</p>
<p dir="auto"><img src="/assets/uploads/files/1607958234591-f4b6837e-4835-431e-83ce-c249c9d49c81-image.png" alt="f4b6837e-4835-431e-83ce-c249c9d49c81-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">So, I’m left wondering why these selection changes happened.<br />
In my mind, proper behavior is to operate on selected text, and then keep the bounds of the starting selection as much as is reasonable, after the replacement.<br />
Clearly, if something happens like the replacement operation removes ALL of the initially selected text, there is nothing to keep, and no selection should remain.<br />
But in other cases…</p>
<p dir="auto">What do others think here?  Bug?  Feature?</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/20470/replaceall-inselection-keeps-selection-sometimes</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Apr 2026 06:44:52 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/20470.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 14 Dec 2020 15:11:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to ReplaceAll InSelection keeps selection...sometimes! on Mon, 14 Dec 2020 15:58:00 GMT]]></title><description><![CDATA[<p dir="auto">BTW, during some of the testing for this, I got into weird situations (one mentioned above) where definitely the <em>In selection</em> checkbox was “out of sync” with how Notepad++ normally handles it.</p>
<p dir="auto">As another example, I had selected text, and the <em>In selection</em> checkbox was not ticked, but when I did a <em>Find All in Current Document</em>, the <em>Find result</em> window said:</p>
<p dir="auto"><code>(0 hits in 0 selections of 1 searched)</code></p>
<p dir="auto">instead of:</p>
<p dir="auto"><code>(0 hits in 0 files of 1 searched)</code></p>
<p dir="auto">So something funky is up with that.</p>
<p dir="auto">I remember a recent poster in another thread had said that even though he had selected-text, the <em>In selection</em> box would not “enable” for him so that he could tick it.  I tend to take that poster a whole lot more seriously now. :-)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/60805</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60805</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 14 Dec 2020 15:58:00 GMT</pubDate></item><item><title><![CDATA[Reply to ReplaceAll InSelection keeps selection...sometimes! on Mon, 14 Dec 2020 15:51:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/14479">@Ekopalypse</a> said in <a href="/post/60802">ReplaceAll InSelection keeps selection...sometimes!</a>:</p>
<blockquote>
<p dir="auto">if \z works with selection, maybe \A does work too?</p>
</blockquote>
<p dir="auto">A good thought, but no, it doesn’t. :-(</p>
]]></description><link>https://community.notepad-plus-plus.org/post/60804</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60804</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 14 Dec 2020 15:51:25 GMT</pubDate></item><item><title><![CDATA[Reply to ReplaceAll InSelection keeps selection...sometimes! on Mon, 14 Dec 2020 15:47:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@Alan-Kilborn</a> said in <a href="/post/60797">ReplaceAll InSelection keeps selection...sometimes!</a>:</p>
<p dir="auto">And, to bring it all “full circle”, my original thinking was that I could get there in one step.  My original statement in this thread:</p>
<blockquote>
<p dir="auto">Problem statement:  Replace (in-selection) all foo to FOO.  Then, Replace (in-selection) all bar to BAR.  Next, put I am  onto the front of the selection.</p>
</blockquote>
<p dir="auto">I started here:</p>
<p dir="auto">find: <code>(^)|(foo)|(bar)</code><br />
repl: <code>(?1I am)(?2FOO)|(?3BAR)</code></p>
<p dir="auto">Which, obviously doesn’t work because of the <code>^</code> usage.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/60803</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60803</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 14 Dec 2020 15:47:03 GMT</pubDate></item><item><title><![CDATA[Reply to ReplaceAll InSelection keeps selection...sometimes! on Mon, 14 Dec 2020 15:46:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@Alan-Kilborn</a></p>
<p dir="auto">if \z works with selection, maybe \A does work too?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/60802</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60802</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Mon, 14 Dec 2020 15:46:32 GMT</pubDate></item><item><title><![CDATA[Reply to ReplaceAll InSelection keeps selection...sometimes! on Mon, 14 Dec 2020 15:42:16 GMT]]></title><description><![CDATA[<p dir="auto">And of course, here’s an inconsistency relating to what I was just discussing concerning <code>^</code>:</p>
<p dir="auto"><code>^</code> won’t work with start-of-selection, but <code>\z</code> will work with end-of-selection</p>
<p dir="auto">See <a href="https://community.notepad-plus-plus.org/post/60727">THIS POSTING</a>, where I said:</p>
<blockquote>
<p dir="auto">with an In selection search, we have to be careful in our thinking about \z being strictly an “end-of-file” thing. In this case it is more of an “end-of-selection” thing. :-)</p>
</blockquote>
]]></description><link>https://community.notepad-plus-plus.org/post/60801</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60801</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 14 Dec 2020 15:42:16 GMT</pubDate></item><item><title><![CDATA[Reply to ReplaceAll InSelection keeps selection...sometimes! on Mon, 14 Dec 2020 15:36:25 GMT]]></title><description><![CDATA[<p dir="auto">So my final operation from above is somewhat interesting (this is separate from the above discussion about what happens to the selection after in-selection replace-all):</p>
<p dir="auto">Using a replacement operation with a selection, how would you simply add some text at its beginning (start of selection), and by “add” I mean simply that, add something and keep what’s there.</p>
<p dir="auto">I did it above by using <code>.+</code> and replacing with <code>I am</code> and a space.</p>
<p dir="auto">[BTW, sharp-eyed readers will note that I screwed up my example because I originally said I wanted to end up with <code>I am FOOBAR</code> but somewhere midstream I changed it to <code>I am BAR</code>.  Dammit!  I really intended replace-with to be <code>I am ${0}</code>.  Well, I guess that isn’t super-important to the point I was trying to make, so…]</p>
<p dir="auto">But anyway, my first thought was to use <code>^</code> to match the start of the selected text.  Well, that quickly fails because this only works if start-of-selection was at the start of a line, due to the nature of <code>^</code>.</p>
<p dir="auto">But that still leaves the question, <em><strong>IS</strong></em> there a good way to match the start-of-selected-text with a regex for this type of replace-in-sel op?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/60800</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60800</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 14 Dec 2020 15:36:25 GMT</pubDate></item><item><title><![CDATA[Reply to ReplaceAll InSelection keeps selection...sometimes! on Mon, 14 Dec 2020 15:18:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@Alan-Kilborn</a> ,</p>
<p dir="auto">Interesting.  My guess is that it’s just an unintended consequence of the way things are done behind the scenes for replace-all-in-selection.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/374">@Scott-Sumner</a> would likely know, given that many of his commits are in the search/replace realm.  You might be able to find him at the gitter-based <a href="https://gitter.im/notepad-plus-plus/notepad-plus-plus" rel="nofollow ugc">live support</a> room – he might be able to give you more insight.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/60798</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60798</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Mon, 14 Dec 2020 15:18:43 GMT</pubDate></item></channel></rss>