If you haven’t done so already, you may want to start by reading the Preface to the Computing Series: Software as a Force Multiplier, Sections 1-3.
1. Notepad++: a programmable, extensible, feature-rich text editor
NotePad++ (NPP) is an open-source programmer’s text editor with outstanding built-in features that can be further enhanced with powerful plugins and extensively customized with your own configurations. NPPs features include syntax highlighting for a large collection of programming languages, code folding, recordable macros, cloned views, selectable shortcuts, tabbed documents, and a host of other capabilities.
But it is the plugins and customization that NPP an invaluable power-tool, capable of far more than text editing. NPP can serve as an automation engine, a complex calculator (for example between hex, binary, and decimal), or a light-weight IDE for any toolchain you wish. It is the second application (after Total Commander) which I install on a Windows computer.
This article describes a few of the dozens of capabilities. It also shares a pre-configured Notepad++ package that I use (20.0MB compressed, 50.0MB uncompressed, download here), which contains the configurations and capabilities I use. The file is portable and self-contained: just unpack NPP to your drive (in a separate folder to your current running instance) and run notepad++.exe from there.1
2. NPP Background & History
NotePad++ is developed by the French software engineer Don Ho first released in September 2003 (2 years after Ho’s graduation with an M.Sc. in Computer Science). The goal of NPP is efficient programming and low CPU consumption (Don Ho has interestingly tied the vision for his editor to be the lowest carbon footprint professional editor out there.) What this means is performance coding is key, for which reason NPP is coded in C++ using direct Win32 API and STL calls. An interview with Don Ho is here, with a little history here. After more than 20 years of development, NPP offers a highly attractive alternative to award-winning commercial proprietary text editors, (e.g. UltraEdit). (see Table 1).
What came before?
Before the arrival of Notepad++, the best text editor at the time was UltraEdit (UE), released in 1994 by Ian D. Mead, a year after Christian Ghisler started Total Commander. Indeed, TC and UE were a pair made for each other, and UE was my text editor of choice, paired with TC as file manager, when I started out in software engineering in 2001. Over the next five years, Notepad++ caught up to UE, and by 2009, NPP was a worthy alternative, and rapidly adding features. After seeing how quickly the column editing feature I had suggested had been implemented, I switched over at NPP v5.2 and haven’t looked back since.
3. Built-in Features and Capabilities
Let’s look at a few of NPP’s capabilities.
- Multi-tab editor. NPP is fast and efficient, able to load and work with dozens of files in memory with no lag and switch cleanly between them. The multi-tab editor makes access easy, and if you have more tabs than can be shown, use the Window Manager (Window > Windows…)
- Language Syntax recognition. NPP recognizes out-of-the-box almost any programming or computing language you are likely to use, and applies styling conventions (all configurable) for easy comprehension. Language syntax add-ons can be easily inserted if there is a future language that arises. Additionally, you can define your own syntax parsers. (See Appendix E)
- Macro recording & Playback (CTRL+SHIFT+R/P). Repetitive tasks can be made vanishingly quick by recording one instance, and then replaying (Ctrl+Shift+P) as many times as desired.
- Column Editing (CTRL+SHIFT+Up/Down).. Column editing is useful when, e.g. inserting the same text in multiple lines simultaneously, e.g. parentheses, spaces, or changing a URL.
- Word Wrap toggle(CTRL+W) allows just the lines, without wrapping long lines (useful e.g. in column-editing mode)
- Line-level Bookmarks (ALT+F2/F2) can be set at any line, making it easy to move back and forth between reference points in a file. ALT+F2 sets the bookmark, F2 jump to the next bookmark.
- Cloning view for side-by-side window for simultaneous viewing/editing of different parts of the same document.
- Find & Replace is better than most and allows matching formatted text (e.g. tabs \t or newlines \n) as well as Regular Expressions (see Appendix C).
- Brace Tracing (Ctrl+SHIFT+B), Code Folding (Alt+0, Alt+SHIFT+1/2/3/…/0), and Font resizing (zoom gestures). For programmers, these little touches are evident everywhere. Font resizing is easier on the eyes and helpful during screen shares or when presenting.
- Configurable Run options. The Run menu is extensible (F5)and can be configured, e.g. to launch a selected URL in default browser using, e.g.
"c:\totalake\FirefoxPortable\FirefoxPortable.exe" "$(CURRENT_WORD)"
(I set the shortcut to Ctrl+F7)
4. Extended Capabilities through Plugins and Add-ons
It is through Plugins that NPP really shines. There are some exceptionally powerful plugins available for it. Here are the 16 which I have found most useful (see Table 2).
- NPP Calc makes NPP into a built-in line by line calculator. But not just for arithmetic, almost all mathematical functions are supported, as well as programmer functions (time/date, geodistance, and many more!). Ctrl+Shift+C toggles active calculation mode. When it’s on, the current line is calculated whenever you press enter. Otherwise highlight the selection to be calculated and press Alt+Enter. See the full list of commands here. Interestingly, while combinations are listed in full, there isn’t an easy combination/permutation counting function, or even a factorial function. For this, use Maxima: e.g.
binomial(5,2)
-
NPP Calc is a Swiss Army Knife plugin. It includes:
- Hex, Decimal, Binary conversion
- Random number generator
- Primality tester & generator
- ASCII code generator
- Math Expression Evaluator
- Color Picker
- Scriptable interfaces, including load file, edit, save, pull from clipboard, take screenshot
- Scriptable network interfaces including test network, send ping, message broadcast
- Unit conversions
Example NPP fileEditors for special needs:
- CudaLister is an excellent colored syntax highlighting viewer and editor for TC Lister
- NppCalc plugin allows immediate evaluation of formulas, including hex,binary,decimal conversions, all within Notepad++ (write the expression, select, Alt+ENTER)
- HxD is a hex editor / binary file viewer and can load files > 4GB without crashing your computer
- JuJuEdit is a large file text editor
- NVU is an editor for HTML
- Programmers fonts distinguish between 0 and O, and 1,l,I, amongst others. Aesthic programmer fonts are Dina and Consolas (used in CudaLister).
- Automation with Macros, NPP Exec, NPP Python Script, Pork2Sausage and NPPEventExec
- Macros record keypresses and built-in NPP commands (next bookmark, next search string, etc.).
- NPP Exec (manual, shortcut creation) allows incorporating console applications, passing input, and pasting output. See Appendix D for examples: (1) inserting a formatted timestamp using Ruby one-liner; (2) running current C file in TCC, etc.
- NPP Python Script can automate a Plugin command (which neither macro record nor NPP Exec can call). This gives even more automated formatting possibilities. For example, we can now do a complex timestamp using NPP Calc’s facilities (see above). The downside is NPP Python Script is a bulky add-on because it requires Python itself, and if you update Python, you can break the script). The upside is NPP Python Script is able to access every single command and menu function in NPP. Using this, one can build a three line script that combines two macros and sandwiches a call to the Plugin:
notepad.runMenuCommand('Macro', 'nppcalc-timestamp') # writes formatted text for NPP Calc, and highlights it
notepad.runPluginCommand('NPPCalc', 'Eval Selected') # calls NPP Calc on the highlighted selection
notepad.runMenuCommand('Macro', 'nppcalc-timestamp-cleanup') # Replaces the format text with the output
The file itself can be saved as timestampy.py and placed in the .\Notepad++\plugins\PythonScript\scripts\timestampy.py
Assigning custom shortcut to this (Ctrl+F5), gives, with one press the timestamp:
2019-07-14---Sun---13:08
- TextFX provides text transformation tools, such as sorting, and more.
- TaskList scrapes a text file for TODO: and pins everything after this in a ToDo list docked to the side of NPP.
- NPP Snippets provides a docked panel which holds commonly used snippets, useful for TeX and other complex boilerplate insertions.
- One of my favorites is NPPtoR, from which NPP becomes the editor for R itself. Write some R code, press F8, and it is sent to RGui and evaluated in R.
- NPP Quick Color Picker runs color chooser GUIs within NPP itself, and inserts the color code selected.
- Dina – The Programmer’s Font – Dina font allows distinguishing similar symbols, essential for programmers to eliminate ambiguity (reduce avoidable bugs!)
Configuring Notepad++ with Dina Programming font.
Install Dina (4 fonts) into Font Control panel. This is enough for NPP. (Note – for Word, you need the Dina TTF (true type fonts))
In NPP: Settings > Style Configurator > Global Font > Select Dina, Select size = 8 pt. Check Enable global font, size, and the 4 style types
More could be written for each of these, and the rest I have not covered. Hopefully, the above is sufficient to illustrate NPP’s potential and entice you to start experimenting. Google is your friend here. There are good discussions on each topic and plugin available on the web.
A few WARNINGS worth sharing:
- Notepad++ does NOT update any of its configuration files UNLESS you close it an re-open.
* So — The danger is that if your computer crashes, all configuration changes that haven’t been followed by an orderly program close will be LOST. - If you make changes to the configuration from the FILE — be careful, because closing Notepad++ will clobber those changes as Notepad++ saves down its current UI based configuration… So either save as… (i.e. temporarily rename, close, then overwrite), OR make changes through the Modify… UI dialogs.
Happy exploring!
6. Next Steps
Download the NPP extensions package I’ve provided, and play around. You can’t damage anything, so feel free to experiment!
- Notepad++ extensions package pre-configured with all plugins etc. (20.0MB compressed, 50.0MB uncompressed)
- Unpack it to
c:\totalcmd\Npp
. This integrates NPP as the external editor within the pre-configured Total Commander package.
Appendix A. Quicklinks & References
- NotePad++ Homepage. 32-bit minimalist package (no themes, no plugins, no update, just unzip and use) (1.43MB compressed download, 4.64MB uncompressed).
- Notepad++ Additional Secrets
- Lifehacker: Getting the most out of Notepad++
- A comparison of competing text editors, including UltraEdit (launched 1994), Emacs, Vim, and Vi, and Microsoft Notepad
- Notepad++ community
- Plugins recently went through a disruptive change (in v7.6) Here’s the manual workaround the plugins break)
- Language syntax understanding comes from Ctags
Appendix B. How do I … ?
- …find the matching brace? Ctrl+B. Built-in capability. Default shortcut.
- …find the matching HTML tag?HTML Tag plugin, Ctrl+T. Included in my package.
- …toggle word wrap on/off to see one line per row?Ctrl+W. Built-in capability. Default shortcut.
- …turn on column edit mode?Alt+Shift+DnArrow. Built-in capability. Default shortcut. Keep pressing till you have all the lines you want to include. Then type or delete or amend and all lines are impacted synchronously.
- …reverse lines?TextFx plugin. Select section to reverse. TextFX Tools > Insert Line Numbers. TextFX Tools > Uncheck Sort ascending. TextFx Tools > Sort lines at column. TextFx Tools > Delete Line Numbers.
- …update modified files silently?
Appendix C. Quick-start to using Regular Expressions.
Regular expressions can be used for search and replace. Below is a quickstart guide. If you understand the 12 principles below, you’ll know enough to cover 90% of the situations. For the rest, the Complete References below provide the detail.
- RegEx are greedy, i.e. they will match as much as possible that fits the criteria, unless ? follows, which makes the match lazy (match least possible). Examples (using Ruby):
def parse_filename1 fn
fn.match(/(^[^.]*)(.*)$/)
return [$1,$2]
enddef parse_filename2 fn # CORRECT!
fn.match(/(^.*)(\..*)$/)
return [$1,$2]
enddef parse_filename3 fn
fn.match(/(^.*?)(\..*)$/)
return [$1,$2]
end
Which is the right one? Try it on the following filenames: “hello” “hello.txt” “hello.world.txt”
Parser 1 explicitly specifies to stop at the first . so will return nil, “.txt” and “.world.txt” respectively.
Parser 2 uses the greedy matching behaviour of Regexes to return nil. “.txt” and “.txt” (correct!)
Parser 3 uses the ? modifier to request lazy matching (stops at first . so returns the same as Parser 1 - All matching is AND, unless pipe | is used to indicate ‘or’ matching. Example: abc|def matches abc or def.
- Special characters are: .[{}()\*+?|^$ These have special meanings (see below), so need to be ‘escaped \’ to reference them directly
- Line boundaries are caret ^ (start of line) and dollar $ (end of line)
- Word boundaries: \< and \> start and end of word
- Dot . signifies any symbol
- Star * means any number of matches (0 or more). Example: .* will match everything
- Plus + means 1 or more matches. Example el+o will match relocate, relocation, hello, yellow, jello
- Character sets: \d any digit, \w any alphanumeric character and underscore, \s whitespace including tab and newline
- Brackets [ ] allow creating customized character sets for matching. Within brackets ^ means “not”. Example: [a^bc^de] matches a single character ace but not bd
- Braces { } specify bounded repeats, e.g. a{3} a{3,} a{3,5} which match a three times, three or more times, and three to five times, respectively
- Parentheses ( ) create a named group that can later be referenced/used in replacement using \1 \2 etc. for the first, second such group.
Complete References: Find reference, Replace reference, NPP list of links
Explanations for Beginners: Micro-Guide.
Appendix D. NPP Exec Examples
NPP Exec is a powerful plugin that brings a highly configurable and user friendly shell/console into Npp.
To get the most use out of Npp Exec you will need to use the Notepad++ Environment Variables
Application 1: Printing formatted timestamp. (custom assigned shortcut Ctrl+F5)
npp_console disable // turn off output display
c:\totalcmd\Ruby\ruby.exe -e "require 'Date'; dt=DateTime.now; dname = Date::ABBR_DAYNAMES[dt.wday]; puts dt.strftime(\"%Y-%m-%d--#{dname}--%H:%M\");"
sel_settext $(OUTPUT)
npp_console enable // turn output display back on
npp_console 0 // hide console window
Application 2: Running current C file using TCC in a separate cmd window. (custom assigned shortcut Ctrl+F6)
SET TCCDIR = c:\totalcmd\tcc
npp_run $(TCCDIR)\tcc\tcc.exe -run -I$(TCCDIR)\include -I$(TCCDIR)\include\winapi -L$(TCCDIR)\lib $(FULL_CURRENT_PATH)
npp_console 0
Appendix E. NPP Syntax Highlighting
NPP supports automatic syntax highlighting for many languages out of the box. If you do not find yours, or want a different highlighting style, you can roll your own.
Language definition files are langs.xml (custom for your NPP installation), langs.model.xml (the master template provided with all NPPs). If you upgrade your NPP, new languages may appear in model but will not appear in langs.xml until/unless you copy paste them over (between <Language> and </Language> tags). This now enables the item in the Preferences > Language menu. (Remember to restart NPP)
Same thing with stylers.xml (custom for your NPP) and stylers.model.xml (master template). You will need to copy-paste over they keywords (between <LexerType> and </LexerType> tags). This now enables the language in the Settings > Edit Styler Configurators… menu. (Remember to restart NPP)
You can then associate custom file extensions to be autorecognized by the syntax highlighting engine:
Settings > Edit Styler Configurators… > find language, e.g. Forth > add User extensions (eg .fs, .4th, .f)
Example: Forth is recognized (.forth) in from 2017 onwards (v7.7.1, 2019 has it in the language menu).
You can also define your own language syntax highlighter.
Appendix F.NPP Internal Command IDs and Scintilla Message IDs
Added Feb 2024
NPPs shortcuts.xml file stores macros that you create in a concise format. However, if you want to modify the macro, it is quite a job to reverse engineer what each line is doing. To do so, you need some reference tables, which I have gathered in this appendix.
If you find this is close to what you need, but you’re missing some details, ask in the comments, and I will elaborate this section.
Table 1: Example Macro in shortcuts.xml
Table 2: Understanding a row of the recorded macro
Reference 3: Searchable list of Scintilla messages
Reference 4: Searchable list of Notepad++ Menu Command IDs
For reference, Notepad++ Command IDs are referenced off the following base numbers:
WM_USER=1024
NPPMSG=2024
IDM 40000
File Menu commands are IDM+1000
Edit Menu commands are IDM+2000
Search Menu commands are IDM+3000
View Menu commands are IDM+4000
Format Menu commands are IDM+5000
Language Menu commands are IDM+6000
About Menu commands are IDM+7000
Settings Menu commands are IDM+8000
Execute Menu commands are IDM+9000
System Tray Notifications are IDM+3100
The full list of individual commands is here, courtesy of the NppExec plugin.
Stay tuned for further articles in this series describing software tools I use to speed things up and build working prototypes fast.
Articles in this series:
- Efficient Computing: using Software as a “Force-Multiplier”
- Total Commander (TC): a powerful two-panel file manager (“why explore when you can command?”)
- Notepad++ (NPP): a programmer’s text editor.
- Everything: an ultra-fast desktop search engine.
Richard Hamming (Applied Mathematician)
“Knowledge and productivity are like compound interest. The more you know, the more you learn; the more you learn, the more you can do; the more you can do, the more the opportunity — it is very much like compound interest.” – Richard Hamming, You and Your Research
- You don’t want to overwrite your current instance, as capabilities are dependent on version of the plugin, and yours may be different than mine. ↩
[…] Notepad++: a programmer’s text editor Home Building a 13-key electronic piano […]
[…] Notepad++ (NPP): a programmer’s text editor. […]
[…] Notepad++: a programmer’s text editor […]