PageRenderTime 3ms CodeModel.GetById 261ms app.highlight 24ms RepoModel.GetById 8ms app.codeStats 0ms


HTML | 164 lines | 164 code | 0 blank | 0 comment | 0 complexity | 7d388ee4c519071a7c666a3a32cb5250 MD5 | raw file
  1<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>&gt;<span class="guimenuitem"><strong>Find</strong></span>
  2            (shortcut: <code class="keycap">C+f</code>) displays the search and replace
  3            dialog box.</p><p>The search string can be entered in the <span class="guibutton"><strong>Search
  4            for</strong></span> text field. This text field remembers previously
  5            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
  6            not span a line break, the selected text becomes the default search
  7            string.</p><p>If the selection spans a line break, the <span class="guibutton"><strong>Search in
  8            Selection</strong></span> and <span class="guibutton"><strong>HyperSearch</strong></span> buttons
  9            will be pre-selected, and the search string field will be initially
 10            blank. (See <a class="xref" href="search-replace.html#hypersearch" title="HyperSearch">the section called &#8220;HyperSearch&#8221;</a> for information about the
 11            HyperSearch feature.) </p><p>Selecting the <span class="guibutton"><strong>Ignore case</strong></span> check box
 12            makes the search case insensitive - for example, searching for
 13            &#8220;<span class="quote">Hello</span>&#8221; will match &#8220;<span class="quote">hello</span>&#8221;,
 14            &#8220;<span class="quote">HELLO</span>&#8221; and &#8220;<span class="quote">HeLlO</span>&#8221;.</p><p>To search for special characters (such as newlines or 
 15            non-printable characters), inexact sequences of text, or strings
 16            that span multiple lines, we use
 17            <span class="bold"><strong>Regular Expressions</strong></span>. 
 18            Selecting the <span class="guibutton"><strong>Regular expressions</strong></span> check
 19            box allows special characters to be used in the search string.
 20            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
 21            <span class="guibutton"><strong>Forward</strong></span> buttons specify the search direction.
 22            Note that regular expressions can only be used when searching in a
 23            forward direction.</p><p>Clicking <span class="guibutton"><strong>Find</strong></span> will locate the next
 24            occurrence of the search string (or previous occurrence, if
 25            searching backwards). If the <span class="guibutton"><strong>Keep dialog</strong></span>
 26            check box is selected, the dialog box will remain open after the
 27            search string has been located; otherwise, it will close.</p><p>If no occurrences could be found and the <span class="guibutton"><strong>Auto
 28            wrap</strong></span> check box is selected, the search will
 29            automatically restart from the beginning of the buffer (or the end,
 30            if searching backwards). If <span class="guibutton"><strong>Auto wrap</strong></span> is not
 31            selected, a confirmation dialog box is shown before restarting the
 32            search.</p><p><span class="guimenu"><strong>Search</strong></span>&gt;<span class="guimenuitem"><strong>Find
 33            Next</strong></span> (shortcut: <code class="keycap">C+g</code>) locates the next
 34            occurrence of the most recent search string without displaying the
 35            search and replace dialog box.</p><p><span class="guimenu"><strong>Search</strong></span>&gt;<span class="guimenuitem"><strong>Find
 36            Previous</strong></span> (shortcut: <code class="keycap">C+h</code>) locates the
 37            previous occurrence of the most recent search string without
 38            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
 39            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
 40            details.</p><p>Clicking <span class="guibutton"><strong>Replace &amp; Find</strong></span> will
 41            perform a replacement in the current selection and locate the next
 42            occurrence of the search string. Clicking <span class="guibutton"><strong>Replace
 43            All</strong></span> will replace all occurrences of the search string
 44            with the replacement string in the current search scope (which is
 45            either the selection, the current buffer, or a set of buffers, as
 46            specified in the search and replace dialog box).</p><p>Occurrences of the search string can be replaced with either a
 47            replacement string, or the return value of a BeanShell script
 48            snippet. Two radio buttons in the search and replace dialog box
 49            select between the two replacement modes, which are described in
 50            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
 51                search string is simply replaced with the replacement
 52                string.</p><p>If regular expressions are enabled, positional parameters
 53                (<code class="literal">$0</code>, <code class="literal">$1</code>,
 54                <code class="literal">$2</code>, and so on) can be used to insert the
 55                contents of matched subexpressions in the replacement string;
 56                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
 57                modify the case of the replacement string to match that of the
 58                particular instance of the search string being replaced. For
 59                example, searching for &#8220;<span class="quote">label</span>&#8221; and replacing it
 60                with &#8220;<span class="quote">text</span>&#8221;, will perform the following
 61                replacements:</p><div class="itemizedlist"><ul type="disc"><li><p>&#8220;<span class="quote">String label</span>&#8221; would become
 62                        &#8220;<span class="quote">String text</span>&#8221;</p></li><li><p>&#8220;<span class="quote">setLabel</span>&#8221; would become
 63                        &#8220;<span class="quote">setText</span>&#8221;</p></li><li><p>&#8220;<span class="quote">DEFAULT_LABEL</span>&#8221; would become
 64                        &#8220;<span class="quote">DEFAULT_TEXT</span>&#8221;</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
 65                replaced with the return value of a BeanShell snippet. The
 66                following predefined variables can be referenced in the
 67                snippet:</p><div class="itemizedlist"><ul type="disc"><li><p><code class="varname">_0</code> -- the text to be
 68                        replaced</p></li><li><p><code class="varname">_1</code> - <code class="varname">_9</code> --
 69                        if regular expressions are enabled, these contain the
 70                        values of matched subexpressions.</p></li></ul></div><p>BeanShell syntax and features are covered in great detail
 71                in <a class="xref" href="writing-macros-part.html" title="Part III. Writing Macros">Part III, &#8220;Writing Macros&#8221;</a>, but here are some
 72                examples:</p><div class="informalexample"><p>To replace each occurrence of &#8220;<span class="quote">Windows</span>&#8221;
 73                    with &#8220;<span class="quote">Linux</span>&#8221;, and each occurrence of
 74                    &#8220;<span class="quote">Linux</span>&#8221; with &#8220;<span class="quote">Windows</span>&#8221;, search for
 75                    the following regular expression:</p><pre class="programlisting">(Windows|Linux)</pre><p>Replacing it with the following BeanShell
 76                    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
 77                    following regular expression:</p><pre class="programlisting">&lt;\S+</pre><p>Replacing it with the following BeanShell
 78                    snippet:</p><pre class="programlisting">_0.toLowerCase()</pre></div><div class="informalexample"><p>To replace arithmetic expressions contained in curly
 79                    braces with the result of evaluating the expression, search
 80                    for the following regular expression:</p><pre class="programlisting">\{(.+?)\}</pre><p>Replacing it with the following BeanShell
 81                    snippet:</p><pre class="programlisting">eval(_1)</pre></div><p>These examples only scratch the surface; the possibilities
 82                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
 83            search and replace dialog box is selected, clicking
 84            <span class="guibutton"><strong>Find</strong></span> lists all occurrences of the search
 85            string, instead of locating the next match.</p><p>By default, HyperSearch results are shown in a floating
 86            window. This window can be docked using the commands in its top-left
 87            corner popup menu; see <a class="xref" href="docking.html" title="Window Docking">the section called &#8220;Window Docking&#8221;</a>.</p><p>If the <span class="guibutton"><strong>Multiple results</strong></span> check box is
 88            selected in the results window, past search results are
 89            retained.</p><p>Running searches can be stopped in the
 90            <span class="guimenu"><strong>Utilities</strong></span>&gt;<span class="guisubmenu"><strong>Troubleshooting</strong></span>&gt;<span class="guimenuitem"><strong>I/O
 91            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
 92            set of files in one step. The set of files to search is selected
 93            with a set of buttons in the search dialog box.</p><p>If the <span class="guibutton"><strong>Current buffer</strong></span> button is
 94            selected, only the current buffer is searched. This is the default
 95            behavior.</p><p>If the <span class="guibutton"><strong>All buffers</strong></span> button is selected,
 96            all open buffers whose names match the glob pattern entered in the
 97            <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
 98            selected, all files contained in the specified directory whose names
 99            match the glob will be searched. The directory to search in can
100            either be entered in the <span class="guibutton"><strong>Directory</strong></span> text
101            field, or chosen in a file selector dialog box by clicking the
102            <span class="guibutton"><strong>Choose</strong></span> button next to the field. If the
103            <span class="guibutton"><strong>Search subdirectories</strong></span> check box is selected,
104            all subdirectories of the specified directory will also be searched.
105            Keep in mind that searching through directories containing many
106            files can take a long time.</p><p>The <span class="guibutton"><strong>Directory</strong></span> and
107            <span class="guibutton"><strong>Filter</strong></span> text fields remember previously
108            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
109            directory and file name filter fields are set to their previous
110            values. They can be set to match the current buffer's directory and
111            file name extension by clicking
112            <span class="guibutton"><strong>Synchronize</strong></span>.</p><p>Note that clicking the <span class="guibutton"><strong>All Buffers</strong></span> or
113            <span class="guibutton"><strong>Directory</strong></span> radio buttons also selects the
114            <span class="guibutton"><strong>HyperSearch</strong></span> check box since that is what you
115            would want, most of the time. However, the
116            <span class="guibutton"><strong>HyperSearch</strong></span> check box can be unchecked, for
117            stepping through search results in multiple files one at a
118            time.</p><p>Two convenience commands are provided for performing multiple
119            file searches.</p><p><span class="guimenu"><strong>Search</strong></span>&gt;<span class="guimenuitem"><strong>Search in Open
120            Buffers</strong></span> (shortcut: <code class="keycap">C+e C+b</code>) displays
121            the search dialog box and selects the <span class="guibutton"><strong>All
122            buffers</strong></span> button.</p><p><span class="guimenu"><strong>Search</strong></span>&gt;<span class="guimenuitem"><strong>Search in
123            Directory</strong></span> (shortcut: <code class="keycap">C+e C+d</code>)
124            displays the search dialog box and selects the
125            <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
126            the current buffer without opening the search dialog box. The search
127            bar does not support replacement or multiple file search. Previously
128            entered strings can be recalled in the search bar with the
129            <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
130            quick search commands (described below) is invoked; however you can
131            choose to have it always visible in the <span class="guibutton"><strong>View</strong></span>
132            pane of the <span class="guimenu"><strong>Utilities</strong></span>&gt;<span class="guimenuitem"><strong>Global
133            Options</strong></span> dialog box; see <a class="xref" href="global-opts.html#view-pane" title="The View Pane">the section called &#8220;The View Pane&#8221;</a>.</p><p><span class="guimenu"><strong>Search</strong></span>&gt;<span class="guimenuitem"><strong>Incremental Search
134            Bar</strong></span> (shortcut: <code class="keycap">C+COMMA</code>) displays the
135            search bar if necessary, and gives it keyboard focus. </p><p><span class="guimenu"><strong>Search</strong></span>&gt;<span class="guimenuitem"><strong>Incremental Search
136            for Word</strong></span> (shortcut: <code class="keycap">A+COMMA</code>) behaves
137            like the above command except it places the word at the caret in the
138            search string field. If this command is invoked while there is a
139            selection, the selection is placed in the search string
140            field instead.</p><p>Unless the <span class="guibutton"><strong>HyperSearch</strong></span> check box is
141            selected, the search bar will perform an <em class="firstterm">incremental
142            search</em>. In incremental search mode, the first occurrence
143            of the search string is located in the current buffer as it is being
144            typed. Pressing <code class="keycap">ENTER</code> and <code class="keycap">S+ENTER</code>
145            searches for the next and previous occurrence, respectively. Once
146            the desired occurrence has been located, pressing
147            <code class="keycap">ESCAPE</code> returns keyboard focus to the text area.
148            Unless the search bar is set to be always visible (see above),
149            pressing <code class="keycap">ESCAPE</code> will also hide the search
150            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
151                your macro needs to perform a search, use the search and replace
152                dialog box instead. See <a class="xref" href="using-macros.html" title="Chapter 8. Using Macros">Chapter 8, <i>Using Macros</i></a> for
153                information about macros.</p></div><p><span class="guimenu"><strong>Search</strong></span>&gt;<span class="guimenuitem"><strong>HyperSearch
154            Bar</strong></span> (shortcut: <code class="keycap">C+PERIOD</code>) displays the
155            search bar if necessary, gives it keyboard focus, and selects the
156            <span class="guibutton"><strong>HyperSearch</strong></span> check box. If this command is
157            invoked while there is a selection, the selected text will be
158            searched for immediately and the search bar will not be
159            shown.</p><p>If the <span class="guibutton"><strong>HyperSearch</strong></span> check box is
160            selected, pressing <code class="keycap">Enter</code> in the search string field
161            will perform a HyperSearch in the current buffer.</p><p><span class="guimenu"><strong>Search</strong></span>&gt;<span class="guimenuitem"><strong>HyperSearch for
162            Word</strong></span> (shortcut: <code class="keycap">A+PERIOD</code>) performs a
163            HyperSearch for the word at the caret. This command does not show
164            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>