Notepad++

User Defined Language

One of the things I like about Notepad++ is that it is easy to define a basic word highlighting format. Notepad++ comes with standard color coded text highlighting for a variety of languages and files types, as does jEdit and other programmers editors. Many other editors also allow you to define your own languages. But the process is fairly easy for Notepad++. Why would you want to do this?

One trick I use is to add custom highlighting to plain txt files. I can then make a checklist where I indicate completed items by placing a “x” before the item.

Here's what that looks like:

Notepad++ Checklist using custom highlighting

To create this formatting, find the “User Define Dialog …” on the View menu.

Menu: View > User Define Dialog ...

I've set the User Language to Text. I'm simply using line comment markup to show a completed item. I've set that comments lines begin with

#, x, //, ' or ! 

I can customize how comments are to appear (green and italic in this case).

The formatting is not contained in the file. If you were to open this file in Microsoft's Notepad it would be just plain text, no highlighting.

User Define Dialog

Regular Expressions

Notepad++ supports regular expressions. It even allows you to capture characters and use them in the Replace string of a Search/Replace operation. If you get into Regex you find there are dialects and idiosyncrasies dependent on where you are using the regex. Notepad++ does not use a complete standard syntax for regex and this may cause you problems. For example a regex expression that works perfectly in Perl or even in jEdit may not work in Notepad++. Still, it is very useful to be able to process text with regex in your text editor. Among the differences between Notepad++ regex and say jEdit regex is that Notepad++ does not support all the common shortcuts or extended syntax. See Notepad++ regex help from the official site.

Here's a simple example of using Regex in Notepad++.

Our example task is to take a list of names that are arranged First Name, Last Name and re-arrange them to be Last Name first. Here's our example list

Adam Apple
Betty Beet
Chris Corn

The regex search expression I used is:

(\w*)\W*(\w*)

The backslash lowercase “w” matches any alphanumeric character. The “\W” matches any whitespace character (space, tab; actually \W is the opposite of \w - it matches any non-alphanumeric character). The asterisks after each means to match any number of characters including none.

The replacement expression is1):

\2, \1

And the result is (as expected):

Apple, Adam
Beet, Betty
Corn, Chris 

Up one level
1) jEdit uses $1 and $2 for replacement text.
 
kb/tools/notepadpp.txt · Last modified: 2009-07-13 11:23 am by admin
Recent changes RSS feed Creative Commons License Driven by DokuWiki
Basically Brilliant! Home
Basically Brilliant! Blog