Searching And Replacing
Looking for text is a very basic functionality even Notepad offers. So is replacing text. Editors differ in the available options, ways to enter text and interaction between the search/replace operation and other editor features.
Notepad++ features 3 search and replace interfaces:
- Regular search/replace dialogs (Search menu)
- TextFX Quick Find/Replace
- Incremental search, on the Search menu.
Since the basic services overlap and are fairly intuitive, this page concentrates on comparing the interfaces and explaining the more advanced options.
Some forms of searching can be performed without invoking any dialog, they will be covered in Dialog free search/mark actions.
- 1 Comparing the offerings
- 2 Highlighting and bookmarking
- 3 Dialog free search/mark actions
- 4 Find in files specific features
- 5 Finding characters in a specific range
- 6 Comparison between "Select and Find Next" and "Find Next (Volatile)"
- 7 Additional features and notes
Comparing the offerings
|Feature / Option||Regular dialog||TextFX dialog||Incremental search|
|Text entry mode|
|Text entry||Search pattern on top, replace on 2nd field if applicable||Search and Replace fields can be swapped using the Swap button||Single entry field|
|Use selection/caret text as default search||Yes||Yes through checkbox||Yes|
|Multiline text||No, but can match end-of-line characters||Yes, use Ctrl+M to mark end of lines||Not supported|
|Special characters||Yes in Extended or RegExp mode||Ctrl+M for newline, Ctrl+T for tab||No|
|Regular expressions||Yes, use radio button||Yes through checkbox||No|
|Find/Replace pattern history||Yes, depth can be set in config.xml||Yes, closing Notepad++ resets||No|
|Editable history||Yes, from config.xml||No||Not applicable|
|Search in files||Find in files mode||Not supported||Not supported|
|Search mode switching||Tab bar||Not available||Not available|
|Next search||Yes, Find button||Yes, Find button||Yes, use < and > buttons|
|Counting||Find All or Count button||Count button||No|
|Incremental search||No||Yes through checkbox||Yes|
|Search range and direction|
|Wraps around document||Yes through checkbox||Yes through checkbox||Always|
|Restrict to selection||Yes if non rectangular and for marking purposes||Yes through checkbox||No|
|Searching direction||Selectable, use radio buttons||Selectable, use radio buttons||Use < and > buttons|
|Match case||Yes through checkbox||Yes through checkbox||Yes through checkbox|
|Whole word matches||Yes through checkbox||Yes through checkbox||No|
|Start of word matches||No except using Regular expressions||Yes through checkbox||No|
|Extra matches on matching line||Yes||Yes through checkbox||Yes|
|Search visible lines only||No||Yes through checkbox||No|
|Adjustable selection||No||Yes, entering col_start-col_end in middle text field||No|
|Batch replace||Yes, in document/opened documents/folder||Yes in current document||Not applicable|
|Replace from position||Yes, se Replace All with Wrap unchecked||Yes, use Replace rest button|
|Protect against recursive replace||Yes||Yes through checkbox|
|Restrict to selection||Yes through checkbox||Yes through checkbox|
|Dialog type||Modeless, user can move||Modeless, user can move||Fixed position above status bar, decreases edit area height|
|Default keyboard shortcut||Ctrl+F / Ctrl+H / Ctrl+Shift+F||Ctrl+R||Ctrl+Alt+I|
|Transparency||Supported, can choose Always or On losing focus||Not supported||Not applicable|
|Result window||Yes, for finding in document/opened documents/folder||No||No|
|Text/pattern not found||Message box reminding of text||"Not found" message in the status bar||Search text field show text with a different (pink) background|
All interfaces close using the Escape key or a button showing a cross, the appearance of which is slightly different for incremental search.
The regular Find/Replace commands and not replaying a macro, when not using the results window, show results in the status bar underneath the dialog. "Results" include error messages and notices that start/end of document was reached.
Highlighting and bookmarking
The Mark tab from the Find/Replace dialog will perform searches similar to the Find tab, in the current document or selection:
- When Bookmark line is checked, a single bookmark is dropped on each line a hit took place.
- Otherwise, the matched pattern is highlighted according to the Settings -> Styler Configurator -> Global Styles , Find Mark Style setting.
In either case, the Mark All button will perform the marking.
To control whether highlighting or bookmarks accumulate over successive searches, use the Clear all marks button to remove marks, or check Purge for each search for this action to be performed automatically on each search.
Highlighting is also available in Incremental search, and the style setting is Settings -> Styler Configurator -> Global Styles , Incremental Highlighting instead.
Dialog free search/mark actions
The following commands, available through the Search menu or keyboard shortcuts, perform a search without invoking a dialog, because they reuse the previous pattern or find it in the current document:
- Find Next / Find Previous repeat the current search, either down or up.
- Go to Next Found / Go to Previous found jump to a place recorded on the search result window. You can use Search -> Found Results Window to toggle the visibility of this window, which allows a more visual navigation.
- Find (volatile) Next / Find (volatile) Previous attempt to find the word the caret is in, or the selected text, down or up. Note that this does not interfere with ordinary search - it is really volatile.
- Select and Find Next / Select and Find Previous select the word the caret is in if no text is selected, and then find the next/previous occurence of selected text. This will also set this word as the current search target, so that Find Next or Find Previous will lose its previous target and look for the selected word again.
Please note that "selected" refers to the contents of the active stream selection. This also applies to the selected part of the caret line when a rectangular area is selected.
TextFX Quick provides what might look as a duplicate for volatile searches: the Mark Word or Find reverse and Mark Word or Find forward entries. They are not complete duplicates though, because they are controlled by two options, Mark Word or Find Case sensitive and Mark Word or Find Whole words. The names should be pretty self-explanatory.
Use the Mark All or Unmark All submenus of the Search menu to mark all occurrences of the word the caret is in. The settings for each of the 5 available styles are Settings -> Styler Configurator -> Global Styles , Mark style #. You can also cause all occurrences of the word at the caret to get dynamically highlighted if you enable Smart Highlighting; the mark style then is Settings -> Styler Configurator -> Global Styles , Smart Highlighting. You may choose there whether the matching should be sensitive to case.
You enable smart highlighting through Settings -> Preferences -> MISC -> Smart highlighting, Enable smart highlighting. By default, the highlighting is case insensitive, which may be a problem sometimes. Then just toggle Settings -> Preferences -> MISC -> Highlighting is case sensitive on.
Find in files specific features
Actually, Find in files allows both finding and replacing. You can choose an extension filter, the containing folder, and whether to also process hidden files or subfolders. The filter list is a space separated list of wildcard expressions that cmd.exe can understand, like "*.doc", "*.*" or "foo.*". Note however that the PathMatchSpec() Windows API is being used, as its behaviour departs from cmd.exe wildcard parsing sometimes.
How the default filter and folder change is controlled by the fifFilterFollowsDoc and fifFolderFollowsDoc settings in config.xml. There is a Follow current doc checkbox to set both parameters to both true or both false.
The extra features from the Find All command are not available while Finding in files. Search options are remembered across invocations, but are lost on Notepad++ shutdown.
Finding characters in a specific range
While regular expressions provide for specifying a range (or multiple ranges) of characters using the [start....end] pattern, this is sometimes awkward when the start or end character isn't easily typed in. Notepad++ provides a specific dialog, available using Find -> Find Characters in range....
As the dialog shows, a custom range of characters can be asked for, as well as either half of the 0..255 range: ASCII covers the lower half, non-ASCII covers the upper part. Note that entries should be in decimal notation, and that values above 255 are not handled in a useful way.
Search may proceed up or down, and optionally wraps around. Hit Find to perform it. Close dialog using either the dedicated button, the close button on the title bar or the Esc key.
Comparison between "Select and Find Next" and "Find Next (Volatile)"
This section is aimed to clear the confusion about these 2 similar commands. Both commands "Select and Find Next" (Ctrl+F3) and "Find Next (Volatile)" (Ctrl+Alt+F3) does the same thing (almost): select the current word (on which caret is) then jump to the next occurrence.
However, there is a slight difference between these 2 commands: "Select and Find Next" remembers the searched word, "Find Next (Volatile)" does not.
Here's an example: If you do "Select and Find Next" command for word word1 then you can always use "Find Next" command (F3) or "Find Previous" command (Shif+F3) to search word1, even the caret is on word2.
If your caret is on word word2, "Find Next (Volatile)" will search the next word2. Now if you move your caret on word word3 and do "Find Next (Volatile)", it will search next word3, and word2 is forgotten.
Additional features and notes
Escape sequences supported in extended mode
In extended mode, and in regular expressions unless stated otherwise, some specific escape sequences (a backslash followed by a single character and optional material), besides the traditional \r, \n and \t. This list only reports sequences supported in extended mode. Pleas consult the whole list of escape sequences supported in Regular Expressions.
- the Line Feed control character LF (ASCII 0x0A)
- The Carriage Return control character CR (ASCII 0x0D)
- the TAB control character (ASCII 0x09)
- the NUL control character (ASCII 0x00). Not supported in regular expressions - use \x00 instead.
- the backalash character (ASCII 0x05C)
- the binary representation of a byte, made of 8 digits which are either 1's or 0's. This has a different meaning in regular expressions (beginning of a word).
- the octal representation of a byte, made of 3 digits in the 0-7 range
- the decimal representation of a byte, made of 3 digits in the 0-9 range
- the hexadecimal representation of a byte, made of 2 digits in the 0-9, A-F/a-f range.
- In extended mode, the hexadecimal representation of a two byte character, made of 4 digits in the 0-9, A-F/a-f range. In Unicode builds, finds a Unicode character. In ANSI builds, finds characters requiring two bytes, like in the Shift-JIS encoding. In regular expressions, this stands for a lowercase letter.
When the current search target is not found, the incremental search text field background changes to a non configurable pink, mimicking Firefox's similar feature.
Shift-clicking the search button allows to search backward rather than forward.
Hitting Enter is equivalent of cycling forward between matches using the ">" button. Shift-Enter similarly cycles backward as the "<" button does.
The result window
- Use up and down arrow to navigate the search result wiindow
- DEL can delete individual results, file matches or whole search matches in the search result window
- The TextFX dialog remembers the starting position, and has a Restore Pos. button to restore it
- As of TextFX version 0.26, the Load and Save buttons only display a not implemented message.
- As of TextFX version 0.26, the Repl. Match case doesn't seem to make any difference. It might be involved in regexp searches.
- See Regular Expressions for supported operators and syntax