Sunday, April 3, 2016

Notepad++ Tips and Tricks

Notepad++ is one of my all-time favorite pieces of software. Whether I'm editing a text file, reviewing log files, or simply using it as a scratch pad to hold an IP address or some other piece of information that I need short-term, I use it virtually every day.

These are some of the useful functions that I've learned over the years. Some of these require additional plugins. To install plugins, go to Plugins > Plugin Manager > Show Plugin Manager.

Don't re-open previous session on startup

By default, Notepad++ will re-open the files from your previous session. While I'm sure that many users like this feature, I personally find it rather annoying.

To disable this, go to Settings > Preferences. Go to the Backup section and uncheck the "Remember current session for next launch" box.


Sorting Text

This requires the TextFX Characters plugin.

Highlight the lines that you want to sort, and go to TextFX > TextFX Tools, and choose whether you want to sort case sensitive or insensitive.





Executing Console Commands

This requires the NppExec plugin.

Thanks to the NppExec plugin, you can have a console embedded within Notepad++. Once you have NppExec installed, hit Ctrl-~ or go to Plugins > NppExec > Show Console Dialog to bring up the console.

The primary use case for this is using Notepad++ for development along with a command-line compiler, but you can perform pretty much any task that you can perform in the native Windows Command Prompt.

It's also more copy/paste friendly than the native Command Prompt. The only gotcha is that you'll have to use Ctrl-C/Ctrl-V because there is no context menu or Edit menu integration.


Comparing the Contents of Two Files

This requires the Compare plugin.

Open two files that you would like to compare, right-click on the tab for one of the files and choose Move to Other view.


This will show your files side-by-side.


Next, hit Alt-D or go to Plugins > Compare > Compare.


When you're done, you can clear the results by pressing Ctrl-Alt-D, or by going to Plugins > Compare > Clear Results.

Find/Replace New Lines

The first thing to do is determine the format of the text file that you're working with. Look at the lower status bar in the area shown below to see the format of the file that you're currently working with.


Open the standard replace dialog box by going to Edit > Replace or pressing Ctrl-H, and set the search mode to Extended.


Enter the appropriate newline character for the format of your file in the "Find what:" box, and whatever you want to replace it with in the "Replace with" box. The newline characters are:

Dos/Windows: \r\n
Unix: \n
Macintosh: \r

If you're curious about what the difference is between \r and \n, this thread on Stack Overflow has a good explanation.

Replacing new lines with commas