Skip to content
Oleg Shilo edited this page Nov 13, 2019 · 6 revisions

NppScripts - Notepad++ Automation Scripts

A Notepad++ plugin for automating Notepad++ operations with C#-based scripting.

The plugin can be used for simple macro-style operations like programmatically modifying the document content. As well as developing complex full scale plugins that are nothing else but dynamically loaded C# scripts. The plugin comes with the intensive library of samples and the wizard for creating new scripts.

The plugin architecture is based on two major sub-systems.

  • NotepadPlusPlusPluginPack
    Rather brilliant .NET-based hosting solution for Notepad++ plugins. The strongest key point of this solution is that it is the only .NET hosting solution that supports both x86 and x64 distributions of Notepad++.
  • CS-Script
    A CLR based scripting system which uses ECMA-compliant C# as a programming language. CS-script allows direct execution of the scripts written in C# without the need to compile them in the assembly.

Additional documentation

Functionality

  • An automation script can use any functionality exposed by the editor hosting interface.
    • Complete Scintilla API
    • Adding Notepad++ menu items
    • Adddding Notepad++ toolbar items
    • Create custom WinForm based panels
  • An automation script can implement any complex business logic allowed by canonical C# syntax.

Installation

You can install the plugin from the Plugins Admin panel. It will be there under the name "NppScripts".

If for whatever reason the plugin is not available there you can always install it manually from the package found in Releases page. Just unpack the content of the NppScripts.zip in the Notepad++ plugin directory and you are done.

Usage

The easiest way of exploring the plugin functionality is to brows the samples library. You can access via Script Manager from Notepad++ menu: 'Plugins'->'Automation Scripts'->'Script Manager'. The names of the scripts reflect their nature. You can run the selected script and see its effect. You can modify the script and run it without immediately.

You can create a new automation script by create a new script:


When implementing your scripts you have a few API options:

  • You can use one of the IScintillaGateway methods scrupulously provided by the NotepadPlusPlusPluginPack.Net environment. in most of the case the name of the method will be the name of the Scintilla or Notepad++ message:

    var path = Npp.Editor.GetFilePath();
    Npp.Document.ReplaceSel(path);
  • Though if for whatever reason you prefer more traditional plugin model by sending Windows messages to the editor or Scintilla document you can rely on low level Win32 API:

    string path;
    Npp.Editor.SendMessage(NppMsg.NPPM_GETFILENAME, 0, out path);
    
    fixed (byte* textPtr = text.ToBytes())
    {
        Npp.Document.SendMessage(scintilla, SciMsg.SCI_REPLACESEL, Unused, (IntPtr)textPtr);
    }

Hints and Tips

When it comes to editing the scripts you can use Notepad++. Of course :o) But if you want to make your development experience core consistent with a typical IDE experience it is recommended you install CS-Script plugin, which allows brings proper intellisense and other typical IDE features. But what is even more important is that with CS-Script plugin you can use a canonical "Go to Definition" (F12) to explore the whole API directly in Notepad++.

Alternatively you can always edit your scripts with Visual Studio. Just select the script in the Script Manager and press the "Open with Visual Studio" button at the bottom toolbar:

Clone this wiki locally