Grep-like functionality for Notepad++?

Ctrl+F --> go to the Mark tab --> toggle Bookmark line --> Click Mark All.

Select menu Search --> Bookmark --> Copy Bookmarked Lines.


I was just looking into this same question. I am not sure if you're aware; in the Find dialog, you can Find All in Current Document which will pop up a window at the bottom showing the matching lines. Then you can copy that into a new document.

Unfortunately, it includes some extraneous information in the results (line number, etc.), but you can filter that out using column mode.


Another great solution is to use the NppExec plugin to add a grep command for Notepad++.

The main advantage over the "Bookmarks" solution is that it runs much faster especially for large files and you don't have to modify your original file. Note that you have to create a small script once to make this feature available in your Notepad++.

My solution example is for Windows and I use findstr, which is a grep-like command tool available on all Windows machines. But you can of course also use any other grep clone of your choice.

Step 1: Install NppExec plugin

Go to Plugins / Plugin Manager / Show Plugin Manager, scroll down to NppExec, select this plugin and click on Install. You may have to restart your Notepad++ to complete the installation process.

Step 2: Create a small script for NppExec

Go to Plugins / NppExec / Execute, enter the following script and save it as "grep":

SET local OUTFILE = "c:\temp\$(FILE_NAME).temp"
INPUTBOX "Input filter string"
cmd /c findstr $(INPUT) "$(FULL_CURRENT_PATH)" >$(OUTFILE)
NPP_OPEN $(OUTFILE)

(please double-check if the path for the OUTFILE works for your environment)

Step 3: Add a menu item for your script (Optional)

Go to Plugins / NppExec / Advanced Options, choose the script "grep" under Associated script and click OK to save. Restart Notepad as requested by NppExec to complete adding the new menu item.

Step 4: Add a shortcut for your script (Optional)

Go to Settings / Shortcut Mapper / Plugin commands, scroll down to find your script command "grep" and define a shortcut for it. e.g. ALT-G

Tags:

Grep

Notepad++