<?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[Python script to replace on selection]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I’m using Python Sscript plugin v1.0.8.0 and I created a script to replace charaters and words.<br />
The full script is below</p>
<p dir="auto">with open(‘D:/config/Notepadpp/replace_char_list.txt’) as f:<br />
for l in f:<br />
s = l.split()<br />
if s[0] == " ":<br />
editor.replace(s[0], " ")<br />
else:<br />
editor.replace(s[0], s[1])</p>
<p dir="auto">And here is the contents of the input file</p>
<p dir="auto">‘ ’<br />
’ ’<br />
&amp;lsquo; ’<br />
&amp;rsquo; ’<br />
“ "<br />
” "<br />
&amp;ldquo; "<br />
&amp;rdquo; "<br />
&amp;nbsp;</p>
<p dir="auto">What I’d like to do is to replace only on selection. I’ve read about editor.replaceSel but I don’t know how to use and I haven’t found any examples on the web.</p>
<p dir="auto">PS: the if statement is there because I couldn’t make the script replace nbsp with a space.</p>
<p dir="auto">Thank you</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/13701/python-script-to-replace-on-selection</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Jul 2026 05:11:51 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/13701.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 22 Apr 2017 23:31:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Python script to replace on selection on Mon, 24 Apr 2017 17:55:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alexceed" aria-label="Profile: AlexCeed">@<bdi>AlexCeed</bdi></a></p>
<p dir="auto">To elaborate a bit on <a class="plugin-mentions-user plugin-mentions-a" href="/user/claudia-frank" aria-label="Profile: Claudia-Frank">@<bdi>Claudia-Frank</bdi></a> 's explanation, here’s some code that shows how to do a replace on only the text in one or more selections:</p>
<pre><code>find = 'a'
replace = 'A'
num_selections = editor.getSelections()
for sel_nbr in range(num_selections):
    start_pos = editor.getSelectionNStart(sel_nbr)
    end_pos = editor.getSelectionNEnd(sel_nbr)
    editor.replace(find, replace, 0, start_pos, end_pos)
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/23857</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23857</guid><dc:creator><![CDATA[Scott Sumner]]></dc:creator><pubDate>Mon, 24 Apr 2017 17:55:20 GMT</pubDate></item><item><title><![CDATA[Reply to Python script to replace on selection on Sun, 23 Apr 2017 20:30:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alexceed" aria-label="Profile: AlexCeed">@<bdi>AlexCeed</bdi></a></p>
<p dir="auto">as the help states it replaces the selected text but from your responds<br />
I understand that you want to, let’s say’ select 4 lines and within this 4 lines<br />
you want to do a search and replace, correct?</p>
<p dir="auto">If this is the case you need to use the getSelection functions,<br />
most probably getSelectionStart() and getSelectionEnd() and use your<br />
replace with the returned start and end position.</p>
<p dir="auto">Cheers<br />
Claudia</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23805</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23805</guid><dc:creator><![CDATA[Claudia Frank]]></dc:creator><pubDate>Sun, 23 Apr 2017 20:30:45 GMT</pubDate></item><item><title><![CDATA[Reply to Python script to replace on selection on Sun, 23 Apr 2017 20:22:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/claudia-frank" aria-label="Profile: Claudia-Frank">@<bdi>Claudia-Frank</bdi></a><br />
But I need to do a search and replace within the selection. If the first argument is the editor, and second is the text to replace, where do I add the item to search?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23804</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23804</guid><dc:creator><![CDATA[AlexCeed]]></dc:creator><pubDate>Sun, 23 Apr 2017 20:22:50 GMT</pubDate></item><item><title><![CDATA[Reply to Python script to replace on selection on Sun, 23 Apr 2017 16:30:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alexceed" aria-label="Profile: AlexCeed">@<bdi>AlexCeed</bdi></a></p>
<p dir="auto">Open the console and type</p>
<pre><code>&gt;&gt;&gt; help(editor.replaceSel)
Help on method replaceSel:

replaceSel(...) method of Npp.Editor instance
    replaceSel( (Editor)arg1, (object)text) -&gt; None :
        Replace the selected text with the argument text.
</code></pre>
<p dir="auto">The first argument, editor, can always be ignored because you call it from<br />
an editor instance, so you need just to provide the text which should be used to replace the content.</p>
<p dir="auto">Cheers<br />
Claudia</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23788</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23788</guid><dc:creator><![CDATA[Claudia Frank]]></dc:creator><pubDate>Sun, 23 Apr 2017 16:30:46 GMT</pubDate></item></channel></rss>