Finding and Replacing Text

The Search and Replace Bars

Kate has an incremental search bar and a power search and replace bar, which offers the means of entering a replacement string along with a few extra options.

The bars offer the following common options:

Find

This is where to enter the search string. The interpretation of the string depends on some of the options described below.

Match case

If enabled, the search will be limited to entries that match the case (upper or lower) of each of the characters in the search pattern.

The power search and replace bar offers some additional options:

Plain Text

Literally match any occurrence of the search string.

Whole Words

If selected, the search will only match if there is a word boundary at both ends of the string matching, meaning not an alphanumeric character - either some other visible character or a line end.

Escape Sequences

If selected, the Add menuitem at the bottom of the context menu of the text boxes will be enabled and allows you to add escape sequences to the search pattern from a predefined list.

Regular Expression

If selected, the search string is interpreted as a regular expression. The Add menuitem at the bottom of the context menu of the text boxes will be enabled and allows you to add regular expression items to the search pattern from a predefined list.

See Regular Expressions for more on these.

Selection only

If checked, the search and replace will be performed within the selected text only.

Find all

Clicking this button highlights all matches in the document and shows the number of found matches in a small popup.

Finding Text

To find text, launch the incremental search bar with Ctrl+F or from the EditFind... menu item.

This opens the incremental search bar at the bottom of the editor window. On the left side of the bar is a button with an icon to close the bar, followed by a small text box for entering the search pattern.

When you start entering characters of your search pattern, the search starts immediately. If there is a match in the text this is highlighted and the background color of the entry field changes to light green. If the search pattern does not match any string in the text, this is indicated by a light red background color of the entry field and Not found is displayed at the right side of the bar.

Use the Next or Previous button to jump to the next or previous match in the document.

Matches are highlighted even when you close the search bar. To clear this highlighting, press the Esc key.

You can choose whether the search should be case sensitive. Selecting Match Case will limit finds to entries that match the case (upper or lower) of each of the characters in the search pattern.

Click on the button with a green arrow icon at the right side of the incremental search bar to switch to the power search and replace bar.

To repeat the last find operation, if any, without calling the incremental search bar, use EditFind Next (F3) or EditFind Previous (Shift+F3).

Replacing Text

To replace text, launch the power search and replace bar using the EditReplace command, or the Ctrl+R shortcut.

On the upper left side of the bar is a button with an icon to close the bar, followed by a small text box for entering the search pattern.

You can control the search mode by selecting the options Plain Text, Whole Words, Escape Sequences or Regular Expression described above.

Use the Next or Previous button to jump to the next or previous match in the document.

Enter the text to replace with in the text box labelled Replace and click the Replace button to replace only the highlighted text or the Replace All button to replace the search text in the whole document.

You can modify the search and replace behaviour by selecting the different options at the bottom of the bar. Selecting Match Case will limit finds to entries that match the case (upper or lower) of each of the characters in the search pattern. Selection Only will search and replace within the current selection only. The Find All button highlights all matches in the document and shows the number of found matches in a small popup.

Click on the button with a green arrow icon at the right side of the power search and replace bar to switch to the incremental search bar.

Tip

If you are using a regular expression to find the text to replace, you can employ backreferences to reuse text captured in parenthesized subpatterns of the expression.

See Regular Expressions for more on those.

Tip

You can do find, replace and ifind (incremental search) from the command line.