Finding and Replacing Text

Finding and Replacing Text

The Find Command

The ‘Find’ command can be invoked 3 ways:

  • By selecting Edit->Find... from the menubar

  • You can use the keyboard shortcut:Ctrl+F

  • By clicking on the toolbar.

When the Find Command is invoked, a dialog appears.

Basic Text Search

The drop-down box labelled Text to Find, provides a place for you to enter the text of your search command. (In the screenshot, that box is currently filled with KDE)

If you click on OK, then KWord will search the document until it finds a match to your text. If KWord cannot find a match, a dialog box will appear that says No match found.

Подсказка

If you want to repeat a recent search, simply select the arrow in the drop-down box and a list of your most recent searches will appear. Simply select your search from the list and click OK.

Refining Your Search

KWord's find feature is much more sophisticated than we discussed above. Using the options in the dialog box, you can narrow down your search to find exactly what you want.

Pattern Matching

The default action for KWord is to search for an exact match of the text. KWord has the ability to match text that follows a pattern or a set of rules.

To enable patterns, place a mark in the box labeled Use Patterns.

This will enable the Insert Pattern button. This button can be a quick way to add patterns for people unfamiliar with UNIX® pattern matching.

Замечание

You do not need to use the Insert Pattern button, to insert your text string. You can type it into the search line. The Insert Pattern button is a convenience for people unfamiliar with pattern matching.

You should now type the text in place, stopping to insert the pattern elements where necessary.

For specific information on pattern matching, take a look at the section entitled Pattern Matching

Formatting options

KWord also has the ability to search your document for text that matches certain formatting options as well as the text itself.

To include formatting options in your search, click the button labeled Show Formatting Options.

Once Show Formatting Options has been clicked, a new dialog will appear.

You can use this dialog to select the options you want to include in your search.

The left column consists of nine checkboxes. If there is a mark in the checkbox, then KWord will evaluate any searchable text for that property. If no mark is in the checkbox, KWord does not consider that property when performing a search.

Family:

Use this drop down box to select the font family you want to include in your search text.

Size:

Use this spin box to set the font size you want KWord to search for.

Color: and Background Color:

Clicking on either of these two buttons allows you to select the font color and/or background color respectively, you want KWord to search for. For more information on selecting a color, see the section on Selecting Colors from the Color Dialog.

Bold: and Italic:

Use these Yes/No radio boxes to determine whether you want KWord to include boldface or italicized fonts in the search text.

Strikeout:

You can select Simple, Double, Simple bold or Without to modify your search.

Underline:

You can select Simple, Double, Simple bold or Without to modify your search.

Vertical Alignment:

You can select Normal, Superscript or Subscript to determine what font alignment you want KWord to search for.

Once you have selected your options, click OK to accept your search options.

Click Cancel to ignore all changes.

Click Reset to restore the options dialog box to the default values.

Click Clear to remove all marks from the checked options.

Other Search options

In addition to pattern matching, you can limit the search results with a few useful options.

Case Sensitive

When this option is selected, KWord will not only search for the string of letters, but will verify that the case of the letters is the same. For example. Searching for:

KDE

will match:

KDE and hiddenKDEinwords but not:

Kde, kde or hiddenkdeinwords.

Find backwards

This option changes the direction of the search. This can be useful when you only want to search for a string of text before the current cursor position, not after. This option is usually used in conjunction with From Cursor, but if that option is not specified, KWord will start searching from the end of the document backwards.

Whole words only

When this option is selected, KWord will only return search items that are surrounded by spaces, paragraph marks or punctuation. For example. Searching for: KDE

will match: KDE

but not: hiddenKDEinwords or KDElike.

Selected Text

If you want to limit your search to a specific part of the document (a few paragraphs, for example), you can select the part of the document you want to search prior to selecting the Find command. When text is selected, KWord will default to only searching the selected text. You can use this option to enable or disable this restriction.

Замечание

This option will not be available if you have not selected text prior to selecting the Find command.

From Cursor

By default, KWord begins searching at the beginning of the document. If this option is selected, KWord begins its search from the current position of the cursor. The direction that KWord searches is, by default forward in the document, but can be changed with the Find Backwards option.

The Replace Command

The replace command is an extension of the find command. If you are familiar with the find command, you will see many similarities.

The Replace command can be invoked 2 ways:

  • By selecting Edit->Replace... from the menubar

  • You can use the keyboard shortcut: Ctrl+R

When the Replace command is invoked, a dialog appears.

Basic Search and Replace

The drop-down box labeled Text to find:, provides a place for you to enter the text of your search command. (In the screenshot, that box is currently filled with KDE)

You can enter your replacement text in the text box labeled Replacement Text:. You can now click OK to replace all occurrences in the document, or you can further refine your search.

Refining Your Search

KWord's find feature is much more sophisticated than we discussed above. Using the options in the dialog box, you can narrow down your search to find exactly what you want.

Pattern Matching

The default action for KWord is to search for an exact match of the text. Fortunately, however, KWord has the ability to match text according to patterns.

To enable patterns, place a mark in the box labeled Use Patterns.

This will enable the Insert Pattern button. This button can be a quick way to add patterns for people unfamiliar with UNIX® pattern matching.

Замечание

You do not need to use the Insert Pattern button, to insert your text string. You can type it into the search line. The Insert Pattern button is a convenience for people unfamiliar with pattern matching.

For specific information on pattern matching, take a look at the section entitled Pattern Matching

Formatting options

KWord also has the ability to search your document for text that matches certain formatting options as well as the text itself.

To include formatting options in your search, click the button labeled Show Formatting Options.

Once Show Formatting Options has been clicked, a new dialog will appear.

You can use this dialog to select the options you want to include in your search.

The left column consists of nine checkboxes. If there is a mark in the checkbox, then KWord will evaluate any searchable text for that property. If no mark is in the checkbox, KWord does not consider that property when performing a search.

Family:

Use this drop down box to select the font family you want to include in your search text.

Size:

Use this spin box to set the font size you want KWord to search for.

Color: and Background Color:

Clicking on either of these two buttons allows you to select the font color and/or background color respectively, you want KWord to search for. For more information on selecting a color, see the section on Selecting Colors from the Color Dialog.

Bold: and Italic:

Use these Yes/No radio boxes to determine whether you want KWord to include boldface or italicized fonts in the search text.

Strikeout:

You can select Simple, Double, Simple bold or Without to modify your search.

Underline:

You can select Simple, Double, Simple bold or Without to modify your search.

Vertical Alignment:

You can select Normal, Superscript or Subscript to determine what font alignment you want KWord to search for.

Once you have selected your options, click OK to accept your search options.

Click Cancel to ignore all changes.

Click Reset to restore the options dialog box to the default values.

Click Clear to remove all marks from the checked options.

Replace with formatted text

KWord also has the ability to replace the found text with formatted text.

To include formatting options in your search, click the button labeled Show Formatting Options in the Replace with section.

Clicking No options disables all previous formatting options selections. This ensures that KWord changes the text, but not the formatting of the text (bold text will remain boldface, superscript text will remain superscript, etc).

Once Show Formatting Options has been clicked, a new dialog will appear.

You can use this dialog to select the format of the replaced text.

The left column consists of nine checkboxes. If there is a mark in the checkbox, then KWord will change any replaced text to match the property selected. If no mark is in the checkbox, KWord does not consider that property when replacing text.

Family

Use this drop down box to select the font family you want your replacement text to use.

Size

Use this spin box to set the font size you want KWord to use for your replaced text.

Color and Background Color

Clicking on either of these two buttons allows you to select the font color and/or background color respectively, you want KWord to use. For more information on selecting a color, see the section on Selecting Colors from the Color Dialog.

Bold and Italic

Use these Yes/No radio boxes to determine whether you want KWord to change the fonts to boldface or italicized fonts.

Strikeout

You can select Simple, Double, Simple bold or Without to use for the replacement text.

Underline

You can select Simple, Double, Simple bold or Without to use for the replacement text.

Vertical Alignment

You can select Normal, Superscript or Subscript to determine what font alignment you want KWord to use.

Once you have selected your options, click OK to accept your text options.

Click Cancel to ignore all changes.

Click Reset to restore the options dialog box to the initial values prior to making any changes.

Click Clear to remove all marks from the checked options.

Using placeholders

Placeholders are useful when you want to add text to complex search strings. Currently KWord has only one placeholder: Complete text string.

This placeholder will contain the entire text string matched by the find command.

For example:

You create a search string, using patterns: Reference \d

Now in the Replace With section of the replace dialog, you place a mark in the checkbox labeled Use placeholders. Click the Insert Placeholder button and select Complete text found. KWord will insert a /0 in the Replacement text text box.

Now surround the placeholder with parentheses, so your text string is: (/0)

When this is executed, whenever KWord encounters the find text (ie. ‘Reference 0’, ‘Reference 1’, ‘Reference 2’, etc) it will surround the text in parethesis (‘(Reference 0)’, ‘(Reference 1)’, ‘(Reference 2)’, respectively).

As you can see, the placeholder will maintain a copy of the search text. You can use this placeholder to add text to the ends of any search string you can imagine.

Other Replace Options

Additional options in the dialog are:

Case Sensitive

When this option is selected, KWord will not only search for the string of letters, but will verify that the case of the letters is the same. For example. Searching for: KDE

will match: KDE and hiddenKDEinwords but not: Kde, kde or hiddenkdeinwords.

Find backwards

This option changes the direction of the search. This can be useful when you only want to search for a string of text before the current cursor position, not after. This option is usually used in conjunction with From Cursor, but if that option is not specified, KWord will start searching from the end of the document backwards.

Whole words only

When this option is selected, KWord will only return search items that are surrounded by spaces, paragraph marks or punctuation. For example. Searching for: KDE

will match: KDE

but not: hiddenKDEinwords or KDElike.

Selected Text

If you want to limit your search to a specific part of the document (a few paragraphs, for example), you can select the part of the document you want to search prior to selecting the Find command. When text is selected, KWord will default to only searching the selected text. You can use this option to enable or disable this restriction.

Замечание

This option will not be available if you have not selected text prior to selecting the Find command.

From Cursor

By default, KWord begins searching at the beginning of the document. If this option is selected, KWord begins its search from the current position of the cursor. The direction that KWord searches is, by default forward in the document, but can be changed with the Find Backwards option.

Prompt on Replace

If this option is selected, KWord will prompt the user before each replacement. This allows you to approve or disapprove each replacement.

Pattern Matching

Sometimes, you want to find or replace text that is similar, but not exactly the same.

KWord allows you to search for words that are similar in certain very well defined ways. This is done through pattern matching.

Each pattern matching string is detailed below. The true power of pattern matching is combining multiple elements into a single search string.

Any Character

Will find any one letter, number, punctuation or symbol. Once selected, KWord will insert a period (.) into your string.

Thus: KW.rd will find or replace KWord, KW2rd, KWOrd or KW*rd.

It will not find or replace: KWoord.

Start of Line

Will find any instance where the start of the line is at this point in the search string. Once selected, KWord will insert a (^) into your string.

Thus: ^KWord will find or replace any instance of KWord which begins a new line.

End of Line

Will find any instance where the end of the line is at this point in the search string. Once selected, KWord will insert a dollar sign ($) into your string.

Thus: KWord$ will find or replace any instance of KWord which occurs at the end of a line.

Set of characters

Once selected, KWord will insert a set of square brackets into your string. KWord will match any characters contained within that set of brackets.

Thus: KW[ao]rd will find or replace any instance of KWord or KWard.

It will not match: KWaord or KWird.

Repeats, zero or more times

Once selected, KWord will insert an asterisk (*) into your string. KWord will match any string of text that contains zero or more of the previous characters behind the asterisk.

Thus: KWo*rd will find or replace any instance of KWrd (zero) or KWord (one), or KWoooooooooord (ten).

It will not match: KWaord or KWird.

Repeats, one or more times

Once selected, KWord will insert a plus sign (+) into your string. KWord will match any string of text that contains one or more of the previous characters behind the asterisk.

Thus: KWo*rd will find or replace any instance of KWord (one), or KWoooooooooord (ten).

It will not match: KWrd (zero).

Optional

Once selected, KWord will insert a question mark (?) into your string. KWord will match any instance of the string if the previous character exists and if it does not

Thus: KWo?rd will find or replace any instance of KWord, or KWrd.

It will not match: KWoord.

Escape

Once selected, KWord will insert a back slash (\) into your string. This backward slash tells KWord to not perform pattern matching with the next character. This is useful when you want to search for a string of text using patterns, but you need to match one of the reserved pattern matching characters.

For example: KW\.rd will find or replace any instance of KW.rd.

It will not match: KWrd.

Подсказка

This character is obviously most useful when you combine it with other pattern matching (not like the example above).

Example: KWord\.* which will match KWord, KWord. and KWord...

This string tells KWord to look for any instance of KWord with zero or more periods (.) at the end.

TAB

Once selected, KWord will insert a back slash folllowed by a t (\t) into your string. KWord will match any string of characters with a tab character (for use with tab stops) in that portion of the string.

Newline

Once selected, KWord will insert a back slash folllowed by a n (\n) into your string. KWord will match any string of characters with a newline character in that portion of the string. (Newline characters are also referred to as Line Breaks).

Подсказка

A newline character is inserted into a KWord document by clicking Shift+Return

Carriage Return

Once selected, KWord will insert a back slash folllowed by a r (\r) into your string. KWord will match any string of characters with a carrage return character in that portion of the string.

Замечание

A carrage return is the same thing as a new paragraph. When you press the Enter key, you are entering a carrage return.

Whitespace

Once selected, KWord will insert a back slash folllowed by a s (\s) into your string. KWord will match any string of characters with a whitespace character in that portion of the string.

Замечание

Whitespace characters is a group of characters that change the flow or move the text around. Examples of whitespace characters are spaces, tabs, and carrage returns.

Digit

Once selected, KWord will insert a back slash folllowed by a d (\d) into your string. KWord will match any string of characters with a numerical digit (any number 0-9) in that portion of the string.

KDE Logo