/www/tags/NOV_07_2009/htdocs/users-guide/search-replace.html
HTML | 164 lines | 164 code | 0 blank | 0 comment | 0 complexity | 7d388ee4c519071a7c666a3a32cb5250 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
- <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Search and Replace</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="jEdit 4.3 User's Guide"><link rel="up" href="editing.html" title="Chapter 5. Editing Text"><link rel="prev" href="markers.html" title="Markers"><link rel="next" href="source-edit.html" title="Chapter 6. Editing Source Code"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Search and Replace</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="markers.html">Prev</a> </td><th width="60%" align="center">Chapter 5. Editing Text</th><td width="20%" align="right"> <a accesskey="n" href="source-edit.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="search-replace"></a>Search and Replace</h2></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2557904"></a>Searching For Text</h3></div></div></div><p><span class="guimenu"><strong>Search</strong></span>><span class="guimenuitem"><strong>Find</strong></span>
- (shortcut: <code class="keycap">C+f</code>) displays the search and replace
- dialog box.</p><p>The search string can be entered in the <span class="guibutton"><strong>Search
- for</strong></span> text field. This text field remembers previously
- entered strings; see <a class="xref" href="history.html" title="Appendix C. History Text Fields">Appendix C, <i>History Text Fields</i></a> for details.</p><p>If text was selected in the text area and the selection does
- not span a line break, the selected text becomes the default search
- string.</p><p>If the selection spans a line break, the <span class="guibutton"><strong>Search in
- Selection</strong></span> and <span class="guibutton"><strong>HyperSearch</strong></span> buttons
- will be pre-selected, and the search string field will be initially
- blank. (See <a class="xref" href="search-replace.html#hypersearch" title="HyperSearch">the section called “HyperSearch”</a> for information about the
- HyperSearch feature.) </p><p>Selecting the <span class="guibutton"><strong>Ignore case</strong></span> check box
- makes the search case insensitive - for example, searching for
- “<span class="quote">Hello</span>” will match “<span class="quote">hello</span>”,
- “<span class="quote">HELLO</span>” and “<span class="quote">HeLlO</span>”.</p><p>To search for special characters (such as newlines or
- non-printable characters), inexact sequences of text, or strings
- that span multiple lines, we use
- <span class="bold"><strong>Regular Expressions</strong></span>.
- Selecting the <span class="guibutton"><strong>Regular expressions</strong></span> check
- box allows special characters to be used in the search string.
- Regular expression syntax is described in <a class="xref" href="regexps.html" title="Appendix E. Regular Expressions">Appendix E, <i>Regular Expressions</i></a>.</p><p>The <span class="guibutton"><strong>Backward</strong></span> and
- <span class="guibutton"><strong>Forward</strong></span> buttons specify the search direction.
- Note that regular expressions can only be used when searching in a
- forward direction.</p><p>Clicking <span class="guibutton"><strong>Find</strong></span> will locate the next
- occurrence of the search string (or previous occurrence, if
- searching backwards). If the <span class="guibutton"><strong>Keep dialog</strong></span>
- check box is selected, the dialog box will remain open after the
- search string has been located; otherwise, it will close.</p><p>If no occurrences could be found and the <span class="guibutton"><strong>Auto
- wrap</strong></span> check box is selected, the search will
- automatically restart from the beginning of the buffer (or the end,
- if searching backwards). If <span class="guibutton"><strong>Auto wrap</strong></span> is not
- selected, a confirmation dialog box is shown before restarting the
- search.</p><p><span class="guimenu"><strong>Search</strong></span>><span class="guimenuitem"><strong>Find
- Next</strong></span> (shortcut: <code class="keycap">C+g</code>) locates the next
- occurrence of the most recent search string without displaying the
- search and replace dialog box.</p><p><span class="guimenu"><strong>Search</strong></span>><span class="guimenuitem"><strong>Find
- Previous</strong></span> (shortcut: <code class="keycap">C+h</code>) locates the
- previous occurrence of the most recent search string without
- displaying the search and replace dialog box.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2558141"></a>Replacing Text</h3></div></div></div><p>The replace string text field of the search dialog remembers
- previously entered strings; see <a class="xref" href="history.html" title="Appendix C. History Text Fields">Appendix C, <i>History Text Fields</i></a> for
- details.</p><p>Clicking <span class="guibutton"><strong>Replace & Find</strong></span> will
- perform a replacement in the current selection and locate the next
- occurrence of the search string. Clicking <span class="guibutton"><strong>Replace
- All</strong></span> will replace all occurrences of the search string
- with the replacement string in the current search scope (which is
- either the selection, the current buffer, or a set of buffers, as
- specified in the search and replace dialog box).</p><p>Occurrences of the search string can be replaced with either a
- replacement string, or the return value of a BeanShell script
- snippet. Two radio buttons in the search and replace dialog box
- select between the two replacement modes, which are described in
- detail below.</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2558189"></a>Text Replace</h4></div></div></div><p>If the <span class="guibutton"><strong>Text</strong></span> button is selected, the
- search string is simply replaced with the replacement
- string.</p><p>If regular expressions are enabled, positional parameters
- (<code class="literal">$0</code>, <code class="literal">$1</code>,
- <code class="literal">$2</code>, and so on) can be used to insert the
- contents of matched subexpressions in the replacement string;
- see <a class="xref" href="regexps.html" title="Appendix E. Regular Expressions">Appendix E, <i>Regular Expressions</i></a> for more information.</p><p>If the search is case-insensitive, jEdit attempts to
- modify the case of the replacement string to match that of the
- particular instance of the search string being replaced. For
- example, searching for “<span class="quote">label</span>” and replacing it
- with “<span class="quote">text</span>”, will perform the following
- replacements:</p><div class="itemizedlist"><ul type="disc"><li><p>“<span class="quote">String label</span>” would become
- “<span class="quote">String text</span>”</p></li><li><p>“<span class="quote">setLabel</span>” would become
- “<span class="quote">setText</span>”</p></li><li><p>“<span class="quote">DEFAULT_LABEL</span>” would become
- “<span class="quote">DEFAULT_TEXT</span>”</p></li></ul></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2558292"></a>BeanShell Replace</h4></div></div></div><p>In BeanShell replacement mode, the search string is
- replaced with the return value of a BeanShell snippet. The
- following predefined variables can be referenced in the
- snippet:</p><div class="itemizedlist"><ul type="disc"><li><p><code class="varname">_0</code> -- the text to be
- replaced</p></li><li><p><code class="varname">_1</code> - <code class="varname">_9</code> --
- if regular expressions are enabled, these contain the
- values of matched subexpressions.</p></li></ul></div><p>BeanShell syntax and features are covered in great detail
- in <a class="xref" href="writing-macros-part.html" title="Part III. Writing Macros">Part III, “Writing Macros”</a>, but here are some
- examples:</p><div class="informalexample"><p>To replace each occurrence of “<span class="quote">Windows</span>”
- with “<span class="quote">Linux</span>”, and each occurrence of
- “<span class="quote">Linux</span>” with “<span class="quote">Windows</span>”, search for
- the following regular expression:</p><pre class="programlisting">(Windows|Linux)</pre><p>Replacing it with the following BeanShell
- snippet:</p><pre class="programlisting">_1.equals("Windows") ? "Linux" : "Windows"</pre></div><div class="informalexample"><p>To convert all HTML tags to lower case, search for the
- following regular expression:</p><pre class="programlisting"><\S+</pre><p>Replacing it with the following BeanShell
- snippet:</p><pre class="programlisting">_0.toLowerCase()</pre></div><div class="informalexample"><p>To replace arithmetic expressions contained in curly
- braces with the result of evaluating the expression, search
- for the following regular expression:</p><pre class="programlisting">\{(.+?)\}</pre><p>Replacing it with the following BeanShell
- snippet:</p><pre class="programlisting">eval(_1)</pre></div><p>These examples only scratch the surface; the possibilities
- are endless.</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="hypersearch"></a>HyperSearch</h3></div></div></div><p>If the <span class="guibutton"><strong>HyperSearch</strong></span> check box in the
- search and replace dialog box is selected, clicking
- <span class="guibutton"><strong>Find</strong></span> lists all occurrences of the search
- string, instead of locating the next match.</p><p>By default, HyperSearch results are shown in a floating
- window. This window can be docked using the commands in its top-left
- corner popup menu; see <a class="xref" href="docking.html" title="Window Docking">the section called “Window Docking”</a>.</p><p>If the <span class="guibutton"><strong>Multiple results</strong></span> check box is
- selected in the results window, past search results are
- retained.</p><p>Running searches can be stopped in the
- <span class="guimenu"><strong>Utilities</strong></span>><span class="guisubmenu"><strong>Troubleshooting</strong></span>><span class="guimenuitem"><strong>I/O
- Progress Monitor</strong></span> dialog box.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2558516"></a>Multiple File Search</h3></div></div></div><p>Search and replace commands can be performed over an arbitrary
- set of files in one step. The set of files to search is selected
- with a set of buttons in the search dialog box.</p><p>If the <span class="guibutton"><strong>Current buffer</strong></span> button is
- selected, only the current buffer is searched. This is the default
- behavior.</p><p>If the <span class="guibutton"><strong>All buffers</strong></span> button is selected,
- all open buffers whose names match the glob pattern entered in the
- <span class="guibutton"><strong>Filter</strong></span> text field will be searched. See <a class="xref" href="globs.html" title="Appendix D. Glob Patterns">Appendix D, <i>Glob Patterns</i></a> for more information about glob patterns.</p><p>If the <span class="guibutton"><strong>Directory</strong></span> radio button is
- selected, all files contained in the specified directory whose names
- match the glob will be searched. The directory to search in can
- either be entered in the <span class="guibutton"><strong>Directory</strong></span> text
- field, or chosen in a file selector dialog box by clicking the
- <span class="guibutton"><strong>Choose</strong></span> button next to the field. If the
- <span class="guibutton"><strong>Search subdirectories</strong></span> check box is selected,
- all subdirectories of the specified directory will also be searched.
- Keep in mind that searching through directories containing many
- files can take a long time.</p><p>The <span class="guibutton"><strong>Directory</strong></span> and
- <span class="guibutton"><strong>Filter</strong></span> text fields remember previously
- entered strings; see <a class="xref" href="history.html" title="Appendix C. History Text Fields">Appendix C, <i>History Text Fields</i></a> for details.</p><p>When the search and replace dialog box is opened, the
- directory and file name filter fields are set to their previous
- values. They can be set to match the current buffer's directory and
- file name extension by clicking
- <span class="guibutton"><strong>Synchronize</strong></span>.</p><p>Note that clicking the <span class="guibutton"><strong>All Buffers</strong></span> or
- <span class="guibutton"><strong>Directory</strong></span> radio buttons also selects the
- <span class="guibutton"><strong>HyperSearch</strong></span> check box since that is what you
- would want, most of the time. However, the
- <span class="guibutton"><strong>HyperSearch</strong></span> check box can be unchecked, for
- stepping through search results in multiple files one at a
- time.</p><p>Two convenience commands are provided for performing multiple
- file searches.</p><p><span class="guimenu"><strong>Search</strong></span>><span class="guimenuitem"><strong>Search in Open
- Buffers</strong></span> (shortcut: <code class="keycap">C+e C+b</code>) displays
- the search dialog box and selects the <span class="guibutton"><strong>All
- buffers</strong></span> button.</p><p><span class="guimenu"><strong>Search</strong></span>><span class="guimenuitem"><strong>Search in
- Directory</strong></span> (shortcut: <code class="keycap">C+e C+d</code>)
- displays the search dialog box and selects the
- <span class="guibutton"><strong>Directory</strong></span> button.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="search-bar"></a>The Search Bar</h3></div></div></div><p>The search bar feature provides a convenient way to search in
- the current buffer without opening the search dialog box. The search
- bar does not support replacement or multiple file search. Previously
- entered strings can be recalled in the search bar with the
- <code class="keycap">Up</code> and <code class="keycap">Down</code> arrow keys; see <a class="xref" href="history.html" title="Appendix C. History Text Fields">Appendix C, <i>History Text Fields</i></a>.</p><p>By default, the search bar remains hidden until one of the
- quick search commands (described below) is invoked; however you can
- choose to have it always visible in the <span class="guibutton"><strong>View</strong></span>
- pane of the <span class="guimenu"><strong>Utilities</strong></span>><span class="guimenuitem"><strong>Global
- Options</strong></span> dialog box; see <a class="xref" href="global-opts.html#view-pane" title="The View Pane">the section called “The View Pane”</a>.</p><p><span class="guimenu"><strong>Search</strong></span>><span class="guimenuitem"><strong>Incremental Search
- Bar</strong></span> (shortcut: <code class="keycap">C+COMMA</code>) displays the
- search bar if necessary, and gives it keyboard focus. </p><p><span class="guimenu"><strong>Search</strong></span>><span class="guimenuitem"><strong>Incremental Search
- for Word</strong></span> (shortcut: <code class="keycap">A+COMMA</code>) behaves
- like the above command except it places the word at the caret in the
- search string field. If this command is invoked while there is a
- selection, the selection is placed in the search string
- field instead.</p><p>Unless the <span class="guibutton"><strong>HyperSearch</strong></span> check box is
- selected, the search bar will perform an <em class="firstterm">incremental
- search</em>. In incremental search mode, the first occurrence
- of the search string is located in the current buffer as it is being
- typed. Pressing <code class="keycap">ENTER</code> and <code class="keycap">S+ENTER</code>
- searches for the next and previous occurrence, respectively. Once
- the desired occurrence has been located, pressing
- <code class="keycap">ESCAPE</code> returns keyboard focus to the text area.
- Unless the search bar is set to be always visible (see above),
- pressing <code class="keycap">ESCAPE</code> will also hide the search
- bar.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Incremental searches cannot be not recorded in macros. If
- your macro needs to perform a search, use the search and replace
- dialog box instead. See <a class="xref" href="using-macros.html" title="Chapter 8. Using Macros">Chapter 8, <i>Using Macros</i></a> for
- information about macros.</p></div><p><span class="guimenu"><strong>Search</strong></span>><span class="guimenuitem"><strong>HyperSearch
- Bar</strong></span> (shortcut: <code class="keycap">C+PERIOD</code>) displays the
- search bar if necessary, gives it keyboard focus, and selects the
- <span class="guibutton"><strong>HyperSearch</strong></span> check box. If this command is
- invoked while there is a selection, the selected text will be
- searched for immediately and the search bar will not be
- shown.</p><p>If the <span class="guibutton"><strong>HyperSearch</strong></span> check box is
- selected, pressing <code class="keycap">Enter</code> in the search string field
- will perform a HyperSearch in the current buffer.</p><p><span class="guimenu"><strong>Search</strong></span>><span class="guimenuitem"><strong>HyperSearch for
- Word</strong></span> (shortcut: <code class="keycap">A+PERIOD</code>) performs a
- HyperSearch for the word at the caret. This command does not show
- the search bar or give it keyboard focus.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="markers.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="editing.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="source-edit.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Markers </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 6. Editing Source Code</td></tr></table></div></body></html>