Find and Replace

T.C. Hollingsworth

The Find function of many KDE Software Collection applications lets you find specific text in a document, while the Replace function allows you to replace text that is found with different text you provide.

You can find both these functions in the Edit menu of many KDE applications. For more information on this menu, see the section called “The Edit Menu”.

The Find Function

The Find function searches for text in a document and selects it.


The Find window.

Searching for software in KMail's composer window.


To use Find in many applications, go to EditFind... or press Ctrl+F. Then, in the Text to find: text box, enter the text that you want to find.

If Regular expression is checked you will be able to search using regular expressions. Click on Edit to select from and enter commonly used regular expression characters, like White Space or Start of Line. If Kate is installed, you can find more information on writing regular expressions in its documentation.

You can limit the found results by configuring these options:

Case sensitive

Capital and lowercase characters are considered different. For example, if you search for This, results that contain this will not be returned.

Whole words only

By default, when the application searches for text, it will return results even in the middle of other text. For instance, if you search for is it will stop on every word that contains that, like this or history. If you check this option, the application will only return results when the search text is a word by itself, that is, surrounded by whitespace.

From cursor

The search will start from the location of the cursor and stop at the end of the text.

Find backwards

By default, the application searches for the text starting at the beginning of the document, and move through it to the end. If you check this option, it will instead start at the end and work its way to the beginning.

Selected text

Select this option to search only in the text that is currently selected, not the entire document. It is disabled when no text is selected.

The Find function only selects the first match that it finds. You can continue searching by selecting EditFind Next or by pressing F3.


Example of a search.

KMail displays a match for software.


Applications which use the KDE text editor component show a search bar instead of the Find window. See KWrite documentation for additional information on the search bar.


The search bar in Kate.

Searching for software in Kate's search bar.


The Replace Function

The Replace function searches for text in a document and replaces it with other text. You can find it in many application at EditReplace... or by pressing Ctrl+R.


The Replace window.

Replacing food with drink in KMail


The window of the Replace function is separated into 3 sections:

Find

Here you may enter the text you wish to search for. See the section called “The Find Function” for more information on the options provided here.

Replace

Here you may enter the text you wish to replace the found text with.

You can reuse the found text in the replacement text by selecting the Use placeholders checkbox. Placeholders, sometimes known as backreferences, are a special character sequence that will be replaced with all or part of the found text. For instance, \0 represents the entire found string.

You may insert placeholders into the text box by clicking the Insert Placeholder button, then selecting an option from the menu like Complete Match. For example, if you are searching for message, and you want to replace it with messages insert the Complete Match placeholder and add an s. The replace field will then contain \0s.

If Kate is installed, you can learn more about placeholders in the Regular Expressions appendix of its documentation.

Options

This contains all the same options that the Find function does, with one addition:

If the Prompt on replace option is checked a window will appear on every found word, allowing you to confirm whether you would like to replace the found text.

Applications which use the KDE text editor component show a search and replace bar instead of the Replace window. See KWrite documentation for additional information on the search and replace bar.


The search and replace bar.

Replacing kmail with kate in Kate's search and replace bar


Thanks and Acknowledgments

Thanks to an anonymous Google Code-In 2011 participant for writing much of this section.