Home | Tips | Library | Other Authors | Other WP Sites | Writer's Links | Contact | Site Map

Barry MacDonnell's
Toolbox for WordPerfect

Macros, tips, and templates for Corel® WordPerfect® for Windows®
© Copyright 1996-2008 by Barry MacDonnell. All Rights Reserved.

Page updated Jul 12, 2008
WordPerfect Tips
Main tips page | Browse tips

Enhancing the Find and Replace feature

Sidebar

How to efficiently use "Find:" in the Find and Replace (F&R) dialog

Most often you probably just type a word or phrase into the Find field, (possibly) make various selections from the F&R dialog's menu, then either search for the item with one of the Find buttons or replace the item in the document with whatever you typed into the Replace field.

Alternatively, you can

(1) just select the words, then bring up the F&R dialog, and the words will be automatically entered in the Find field; or

(2) select some words, then copy the selection to the clipboard (Ctrl+C or Ctrl+Insert), and then paste (Ctrl+V or Shift+Insert) the words (including embedded symbols or codes) from the document directly into the Find field.

In most cases these two alternatives will not present a problem.

Keep it short!

As with manually typing words into the F&R field, pre-selecting words, or copying a selection and then pasting it into the field is limited by the program to just 79 characters and spaces. If your intent was to search for this selection in the document, this can present a problem if the selection is longer than 79 characters/spaces. (Not to mention that it probably is unnecessary to use such long strings in a find operation!)

One issue is that if you pre-select text that has more than 79 characters, WordPerfect will simply ignore it and not put it in the Find field. This might cause you to wonder why it didn't work when it often worked in the past (with shorter selections).

The reason WordPerfect ignores such larger blocks of selected material is that it assumes you want to search in the selection, not search for the selection. In fact, it will enable "Search in Selection" in the F&R Options menu. It then waits for you to type something in the Find field (it may already have placed the previous search material there).

This is "working as designed," and it might be what you want to do some of the time. Just be aware of what WordPerfect assumes you want to do depending on the size of your selection of material. To search for words in the document, keep the selection short. Otherwise,WordPerfect will set things up to search inside the selection for whatever you type in the Find field.

The "truncation effect"

Another issue: "Characters" in the context of selecting material also means WordPerfect symbols and format codes. So if you copy a short selected block of text that contains these codes, these items are counted toward the 79 "character" limit when you paste them into the Find field (or let WordPerfect automatically insert them in the Find field with alternative #1 above).

Therefore, the sentence might become truncated (cut off at the end) in the Find field. Since the F&R field is relatively small, you might not notice this with a long sentence, and therefore you might not replace what you expect to replace when your click Replace or Replace All.

Moreover, as with merely selecting large blocks of text, copying and pasting a selection larger that 79 characters/codes also causes WordPerfect to enable "Search in Selection" in the F&R Options menu. This is probably not what you want.

Again, it is best to keep your selections short unless you really intend to search inside the selection itself.

[Incidentally, finding and replacing large blocks of text in often-used documents can be done with text variables.]

An alternative

One way to work around the truncation problem (other than to remember to keep selections shortet than 79 characters/codes) is to first paste the copied selection elsewhere in the document (or a blank document) as Unformatted text (see here for more), re-select and re-copy the item, then paste the now unformatted version into the Find field. Again, this might only be needed for sentences that approach 79 characters -- counting any embedded codes.

What about macro searches?

Note that macro search routines are also limited to 79 characters in a SearchString() command; however, storing a selection of text in a macro variable automatically strips out any format codes. The Search (and Replace, if used) operation will succeed since it looks for only the characters and spaces -- up to the 79 character limit, of course. [See the footnote below for a code snippet to test for the length of the selected string.]

The standard Find and Replace dialog has to be dragged from its position in the center of the screen if you want to see the item found or the item to be replaced. Moreover, it does not provide an easy way to replace (or format) just certain instances of an item. Finally, having to repeatedly open the F&R dialog (Edit, Find and Replace, or <Ctrl+F>) to find or replace the same item is tedious.

Here's a tip posted by Pam Britt on WordPerfect Universe that may help:

"To repeat a find once you have closed the dialog box, you need not reopen the box. Simply press <Ctrl+Shift+F> . . . to go to the next occurrence of your designated find text.

[Editor's note: If you use the DOS keyboard instead of the standard Windows keyboard, you will need to assign the "Find and Replace" and "Find Next" features to <Ctrl+F> and <Ctrl+Shift+F>. See the tip about assigning a macro, feature, program, or string of keystrokes to a key or key combination (i.e., a "shortcut" or "hot key"), here.]

This is an extremely efficient tool for the kind of templates I have prepared over the years and through many versions of WP, placing # symbols where I would eventually need to add text and @ symbols where others would need to do so. These and other symbols can be searched to easily and then replaced on the run. (The "find" highlights the character [but see below], and all you have to do is start typing the new text -- no <Escape>, no <Delete>, no nothing. If text (or a symbol) is highlighted and you need to change it, start typing; if you need to go to the next instance, just press <control>+<shift>+f again.)

It is also very simple to replace text using this feature. All that's needed is for you to have already marked for copying [i.e., copied to the clipboard with <Ctrl+C>] the "replace with" text; then, when you hit on an instance where you need the text replaced, paste the "replace with" text over the found text [with <Ctrl+V>]...."

However, sometimes there is a problem with the part of Pam's tip that says -

...The "find" highlights the character, and all you have to do is start typing the new text...

Most of the time this will be true. But if the user has set Edit > Find and Replace > Action to anything other than "Select Match," or plays a macro that sets the Action to another value, then the items found will not be selected (i.e., highlighted in reverse color). The Action menu in Find and Replace is "sticky": settings will persist into the next WP session.

Here's a solution: Create (or download) and play the Find and Replace macro below, which could be assigned to the <Ctrl+F> and/or <F2> key instead of simply the "Find and Replace" feature. It will reset the Find and Replace dialog's settings first; then it will pop up the Find and Replace dialog. This will be completely transparent to the user.

Tip: For your convenience, download the following macro here.

// Find and Replace.wcm - Enhances the use of the standard Find and Replace feature by ensuring that WordPerfect default settings for the F&R dialog are reset -- especially the "Select Match" setting in the Action menu, which normally leaves the item selected (and thus more visible on screen) after it is found.

// For convenience, you can assign this macro to the <Ctrl+F> key and/or <F2> key to replace the standard methods of bringing up the Find and Replace dialog.

If(?DocBlank)
  Messagebox(;"Error";"Document is blank.";IconInformation!)
  Go(End@)
Endif
OnCancel (End@)
pResetFindReplace ()
FindDlg ()

// Set the found item vertically on screen -
QuickmarkSet ()
Display(On!)
QuickmarkFind ()


Label (End@)
Quit

Procedure pResetFindReplace ()
SearchString ("")
ReplaceString ("")
// Only one of these next 4 Match... commands can be active at any one time:
// MatchPositionAfter ()
// MatchExtendSelection()
// MatchPositionBefore()
MatchSelection()
SearchFindWholeWordsOnly (No!)
MatchWithAttributes (No!)
ReplaceWithAttributes (No!)
SearchCaseSensitive (No!)
ReplaceWithCase (No!)
MatchWithFont (No!)
ReplaceWithFont (No!)
MatchWithFontSize (No!)
ReplaceWithFontSize (No!)
SearchInSelection (No!)
SearchWordForms (No!)
SearchWrap (No!)
MatchLimit (No!)
EndProcedure

For help assigning macros to keystroke combinations ("shortcut keys") see here.

In addition to the tip above, here's another related tip:

When the found item is shown selected on screen you can use other standard formatting shortcut keys to quickly make the instance bold, italic, underlined etc. Just press <Ctrl+B> for bold, <Ctrl+I> for italic, etc., while the item is selected. Then simply press <Ctrl+Shft+F> to go to the next instance of the item, if desired.

You might even like to highlight found-and-selected items in the current highlight color. Since there doesn't seem to be a built-in feature in WP's keyboard editor that you can directly assign to a shortcut key for this, use a macro instead. You can assign the small macro below to, for example, the <Ctrl+H> key to toggle highlighting on for the selected item.

Tip: For your convenience, download the following macro here (included with the Find and Replace macro above). Note: If you use the Redaction Tool in the initial release of WordPerfect X4, here are some tips (click here for the PDF version) when using normal highlighting (Tools, Highlight) in the same document that is marked up for redaction (Tools, Redaction).

// Highlight Toggle.wcm - Toggle selected text to highlighted text.
// Assign to <Ctrl+H> or similar key for convenience.

If(?BlockActive)
 PosSelectBottom
  HighlightToggle
Else
 Messagebox(;"Highlight Toggle";"Select some text first!";IconWarning!)
Endif
Quit

Finally, note that redline or strikeout formatting (not to be confused with similar effects produced during a file Compare or Review) are not assigned to any standard shortcut key. However, they can be assigned to one using the "Attribute Redline" and "Attribute Strikeout" choices in the Format feature list, found in the keyboard editor's Keyboard Shortcuts window. Assigning them to <Alt+Ctrl+R> and <Alt+Ctrl+S> or other preferred keys might be handy. Since they do not require that the item be selected first, no macro such as Highlight Toggle above is needed.

For help assigning macros to keystroke combinations ("shortcut keys") see here.



Footnote

For macro writers:

One way to alert the user of a macro that searches for selected text that the selection is too long is to use something like the following snippet in the macro's code after the point where some text has been selected:

vVar:=?SelectedText
vLen:=StrLen(vVar)
If(vLen>79)
  Messagebox(;"Caution - item exceeds 79 characters"; "The item"
  +NToC(0F90Ah)+?SelectedText+NToC(0F90Ah)+"is too long.")
Endif