<?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[How to Insert/Import Text from a Separate File]]></title><description><![CDATA[<p dir="auto">Hello All,</p>
<p dir="auto">I have been using Notepad++ for several years but have never identified a fast way to do this (measured against the same functionality in other apps).</p>
<p dir="auto">I would like to be able to insert text from another file into an open file by:</p>
<ul>
<li>Place the cursor in the target location</li>
<li>Select the command to insert all text from a chosen file on disk (not open in Notepad++) at the target location.</li>
</ul>
<p dir="auto">I have used other editing tools that vary in how one chooses the file to insert using this method.</p>
<ul>
<li>Vi/Vim uses the command <code>:r &lt;filename&gt;</code> to read in the contents of another text file (and achieving the same thing as an insert/import of the text)</li>
<li>MS Word uses its <strong>NON-WORD PROCESSING</strong> command reached by <code>Insert - Object - Text From File</code> to bring up the file picker so one can select the text file to insert at the target location.</li>
</ul>
<p dir="auto">Does Notepad++ have an easier way to make this text file insertion into the current file - without executing something similar to <code>Open (source file), Select all (source file); Copy; Select target location (receiving file); Paste; Close (source file)</code>?</p>
<p dir="auto">Thanks for the help!</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/25395/how-to-insert-import-text-from-a-separate-file</link><generator>RSS for Node</generator><lastBuildDate>Sat, 14 Nov 2026 21:25:02 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/25395.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 22 Jan 2024 16:11:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to Insert/Import Text from a Separate File on Mon, 22 Jan 2024 17:22:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/acmenuclear" aria-label="Profile: AcmeNuclear">@<bdi>AcmeNuclear</bdi></a> said in <a href="/post/92260">How to Insert/Import Text from a Separate File</a>:</p>
<blockquote>
<p dir="auto">Does Notepad++ have an easier way to make this text file insertion into the current file - without executing something similar to Open (source file), Select all (source file); Copy; Select target location (receiving file); Paste; Close (source file)?</p>
</blockquote>
<p dir="auto">Not really.<br />
But if you’re willing to use a scripting plugin, a simple script can be written:</p>
<pre><code class="language-py">from Npp import *
import os
f = notepad.prompt('Enter file name:', '', '')
if f and os.path.isfile(f):
    notepad.open(f)
    editor.selectAll()
    editor.copy()
    notepad.close()
    editor.paste()
</code></pre>
<p dir="auto">The script assumes you have the “MRU” setting selected (otherwise when the script closes the file tab it opens, you won’t be returned to the correct file tab):</p>
<p dir="auto"><img src="/assets/uploads/files/1705943836083-de7fbf65-50c8-42ec-bed9-ec4e218fe5ed-image.png" alt="de7fbf65-50c8-42ec-bed9-ec4e218fe5ed-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">And, yes, this script is very simple.  It intentionally loads the file into Notepad++ (instead of just reading the file with Python) to avoid making non-Notepad++ assumptions about the encoding of the file, it expects you to know the name of the file you want (instead of a “picker”), it will close the to-be-inserted-file if that file happens to be open in N++ when the script is run, etc.).  Many things could be done to make the script more well-rounded.</p>
<p dir="auto">For the basics of scripting, see <a href="https://community.notepad-plus-plus.org/topic/23039/faq-how-to-install-and-run-a-script-in-pythonscript">HERE</a>.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/92265</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/92265</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 22 Jan 2024 17:22:47 GMT</pubDate></item></channel></rss>