Find and replace
The FindAndReplace
feature allows for finding and replacing any text in the editor easily. It helps the user find words, word parts or phrases matching the case of the searched text, which is especially helpful in lengthy documents and one that may utilize certain words in different contexts. It also lets the editor replace a chosen one or all instances of the searched phrase with a single click, making tedious, repeated changes fast and easy. This may e.g. help ensuring the cohesion of an edited piece of code, while renaming a variable or a function.
# Demo
Use the find and replace toolbar button
to invoke the search panel and find and replace desired words or phrases or use the Ctrl/Cmd+F keyboard shortcut. For a starter, try replacing “steam” with “diesel” to make the demo content more up to date. Be careful to match the case, for there are different instances of the word present in the document!# Related features
- Automatic text transformation – Enables automatic turning of snippets such as
(tm)
into™
and"foo"
into“foo”
.
# Installation
To add this feature to your editor, install the @ckeditor/ckeditor5-find-and-replace
package:
Then add the FindAndReplace
plugin to your plugin list:
Read more about installing plugins.
# Common API
The FindAndReplace
plugin registers the 'findAndReplace'
UI button component and the 'find'
, 'findNext'
, 'findPrevious'
, 'replace'
and 'replaceAll'
commands.
The commands can be executed using the editor.execute()
method:
You can also move the highlight through all matched results with the 'findNext'
and 'findPrevious'
commands:
You can also replace all occurrences of a given text in the editor instance using the 'replaceAll'
command:
We recommend using the official CKEditor 5 inspector for development and debugging. It will give you tons of useful information about the state of the editor such as internal data structures, selection, commands, and many more.
# Contribute
The source code of the feature is available on GitHub in https://github.com/ckeditor/ckeditor5/tree/master/packages/ckeditor5-find-and-replace.
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.