Many developers love the multi-selection feature in Visual Studio Code (VSCode), where pressing Ctrl+D
selects the next occurrence of the currently selected text—allowing you to edit multiple places at once.
Notepad++ does not offer this natively, but with the powerful NppExec plugin and some configuration, you can achieve a very similar workflow.
How Multi-Selection Works in VSCode
In VSCode, you can:
- Select a word or text fragment.
- Press Ctrl+D to select the next occurrence of that text.
- Continue pressing Ctrl+D to add more occurrences to your selection.
- Edit all selected instances simultaneously.
This feature is invaluable for refactoring, quick edits, or making the same change in multiple places.
How to Replicate Multi-Selection in Notepad++
Notepad++ does not have this feature out-of-the-box, but you can configure it using the NppExec plugin and the Shortcut Mapper. Here’s how:
- Step 1: Install NppExec Plugin
- Open Notepad++.
- Go to Plugins > Plugins Admin.
- Find and install NppExec.
If you encounter installation issues, you may need admin rights or to manually copy the plugin files to the Notepad++ plugins directory.
- Step 2: Create the Multi-Selection Script
- Go to Plugins > NppExec > Execute….
- In the command window, paste the following script:
npp_console 0
sci_sendmsg SCI_SETSEARCHFLAGS SCFIND_MATCHCASE
sci_sendmsg 2690 // SCI_TARGETWHOLEDOCUMENT
sci_sendmsg 2688 // SCI_MULTIPLESELECTADDNEXT
npp_console 0
hides the NppExec console when running the script.
sci_sendmsg SCI_SETSEARCHFLAGS SCFIND_MATCHCASE
sets the search to be case sensitive.
sci_sendmsg 2690
and sci_sendmsg 2688
are Scintilla commands that select the next occurrence of the selected text in the whole document.
Click Save…, give your script a name (e.g., MultiSelectAddNext
), and save.
-
Step 3: Add the Script to the Menu and Assign a Shortcut
- Go to Plugins > NppExec > Advanced Options.
- Under “Associated Scripts”, select your script and click “Add/Modify”.
- (Optional) Check “Place to the Macros submenu” if you want quick access from the menu.
- Click OK and restart Notepad++ if prompted.
-
Step 4: Assign a Shortcut Key
- Go to Settings > Shortcut Mapper.
- Go to the “Plugin Commands” tab.
- Find your script (e.g.,
MultiSelectAddNext
). - Double-click the “Shortcut” column and assign your preferred shortcut (e.g., Ctrl+D).
If Ctrl+D is already used, you may need to assign a different combination.
Usage
- Select the text you want to find more occurrences of.
- Press your assigned shortcut (e.g., Ctrl+D) to select the next occurrence.
- Repeat to select further occurrences.
- Edit all selected instances at once—just like in VSCode.
Troubleshooting and Tips
If the shortcut opens the NppExec console
, ensure npp_console 0 is at the top of your script.
If your script does not appear in the Shortcut Mapper, make sure you added it via Advanced Options in NppExec.
You can customize the search flags (e.g., for case sensitivity or whole word matching) by changing the value in SCI_SETSEARCHFLAGS.