Warning, /utilities/kate/doc/katepart/advanced.docbook is written in an unsupported language. File is not indexed.
0001 <chapter id="advanced-editing-tools"> 0002 <chapterinfo> 0003 <authorgroup> 0004 <author>&Anders.Lund; &Anders.Lund.mail;</author> 0005 <author>&Dominik.Haumann; &Dominik.Haumann.mail;</author> 0006 <!-- TRANS:ROLES_OF_TRANSLATORS --> 0007 </authorgroup> 0008 </chapterinfo> 0009 <title>Advanced Editing Tools</title> 0010 0011 <sect1 id="advanced-editing-tools-comment"> 0012 0013 <title>Comment/Uncomment</title> 0014 0015 <para>The <guimenuitem>Comment</guimenuitem> and <guimenuitem>Uncomment</guimenuitem> commands, available from the 0016 <guimenu>Tools</guimenu> menu allow you to add or remove comment 0017 markers to the selection, or the current line if no text is selected, 0018 if comments are supported by the format of the text you are 0019 editing.</para> 0020 0021 <para>The rules for how commenting is done are defined in the syntax 0022 definitions, so if syntax highlighting is not used, commenting/uncommenting 0023 is not possible. </para> 0024 0025 <para>Some formats define single line comment markers, some multiline 0026 markers and some both. If multiline markers are not available, 0027 commenting out a selection that does not fully include its last line 0028 is not possible.</para> 0029 0030 <para>If a single line marker is available, commenting single lines is 0031 preferred where applicable, as this helps to avoid problems with 0032 nested comments.</para> 0033 0034 <para>When removing comment markers, no uncommented text should be 0035 selected. When removing multiline comment markers from a selection, 0036 any whitespace outside the comment markers is ignored.</para> 0037 0038 <para><indexterm><primary>comment</primary></indexterm> 0039 To place comment markers, use the 0040 <menuchoice><guimenu>Tools</guimenu><guimenuitem>Comment</guimenuitem></menuchoice> 0041 menu item or the related keyboard shortcut sequence, the default is 0042 <keycombo action="simul">&Ctrl;<keycap>D</keycap></keycombo>.</para> 0043 0044 <para><indexterm><primary>uncomment</primary></indexterm> 0045 To remove comment markers, use the 0046 <menuchoice><guimenu>Tools</guimenu><guimenuitem>Uncomment</guimenuitem></menuchoice> 0047 menu item or the related keyboard shortcut, the default is <keycombo 0048 action="simul">&Ctrl;&Shift;<keycap>D</keycap></keycombo>.</para> 0049 0050 </sect1> 0051 0052 <sect1 id="advanced-editing-tools-commandline"> 0053 <title>The Editor Component Command Line</title> 0054 0055 <para>&kappname;'s editor component has an internal command line, allowing you to 0056 perform various actions from a minimal &GUI;. The command line is a text entry 0057 at the bottom of the editor area; to show it select 0058 <menuchoice><guimenu>View</guimenu><guimenuitem>Switch to Command Line</guimenuitem></menuchoice> 0059 or use the shortcut (default is 0060 <keycombo action="simul"><keycap>F7</keycap></keycombo>). The editor provides 0061 a set of commands as documented below, and additional commands can be provided 0062 by plugins.</para> 0063 0064 <para>To execute a command, type the command then press the return key. The 0065 command line will indicate whether it succeeded and possibly display a message. If 0066 you entered the command line by pressing <keycap>F7</keycap> it will 0067 automatically hide after a few seconds. To clear the message and enter a new 0068 command, press <keycap>F7</keycap> again.</para> 0069 0070 <para>The command line has a built-in help system; issue the command 0071 <command>help</command> to get started. To see a list of all available commands 0072 issue <command>help list</command>; to view help for a specific command, do 0073 <command>help <replaceable>command</replaceable></command>.</para> 0074 0075 <para>The command line has a built in history, so you can reuse commands already 0076 typed. To navigate the history, use the &Up; and 0077 &Down; keys. When showing historical commands, the argument part 0078 of the command will be selected, allowing you to easily overwrite the 0079 arguments.</para> 0080 0081 <sect2 id="advanced-editing-tools-commandline-commands"> 0082 <title>Standard Command Line Commands</title> 0083 0084 <variablelist> 0085 <title>Argument types</title> 0086 0087 <varlistentry> 0088 <term>BOOLEAN</term> 0089 <listitem><para>This is used with commands that turns things on or off. 0090 Legal values are <userinput>on</userinput>, <userinput>off</userinput>, 0091 <userinput>true</userinput>, <userinput>false</userinput>, 0092 <userinput>1</userinput> or <userinput>0</userinput>.</para></listitem> 0093 </varlistentry> 0094 0095 <varlistentry> 0096 <term>INTEGER</term> 0097 <listitem><para>An integer number.</para></listitem> 0098 </varlistentry> 0099 0100 <varlistentry> 0101 <term>STRING</term> 0102 <listitem><para>A string, surrounded by single quotes (') or double quotes (") when it contains spaces.</para></listitem> 0103 </varlistentry> 0104 0105 </variablelist> 0106 0107 0108 0109 <sect3 id="advanced-editing-tools-commandline-commands-configure"> 0110 <title>Commands for Configuring the Editor</title> 0111 0112 <para>These commands are provided by the editor component, and allow you to 0113 configure the active document and view only. This is handy if you want to use 0114 a setting different from the default settings, for example for indentation. 0115 </para> 0116 0117 <variablelist> 0118 0119 <varlistentry> 0120 <term><cmdsynopsis><command>set-tab-width</command><arg choice="req">INTEGER width</arg></cmdsynopsis></term> 0121 <listitem><para>Sets the tab width to the number <userinput>width</userinput>.</para></listitem> 0122 </varlistentry> 0123 0124 <varlistentry> 0125 <term><cmdsynopsis><command>set-indent-width</command><arg choice="req">INTEGER width</arg></cmdsynopsis></term> 0126 <listitem><para>Sets the indentation width to the number 0127 <userinput>width</userinput>. Used only if you are indenting with 0128 spaces.</para></listitem> 0129 </varlistentry> 0130 0131 <varlistentry> 0132 <term><cmdsynopsis><command>set-word-wrap-column</command><arg choice="req">INTEGER width</arg></cmdsynopsis></term> 0133 <listitem><para>Sets the line width for hard wrapping to 0134 <userinput>width</userinput>. This is used if you are having your text wrapped 0135 automatically.</para></listitem> 0136 </varlistentry> 0137 0138 <varlistentry> 0139 <term><cmdsynopsis><command>set-icon-border</command><arg choice="req">BOOLEAN enable</arg> 0140 </cmdsynopsis></term> 0141 <listitem><para>Sets the visibility of the icon border.</para></listitem> 0142 </varlistentry> 0143 0144 <varlistentry> 0145 <term><cmdsynopsis><command>set-folding-markers</command><arg choice="req">BOOLEAN enable</arg></cmdsynopsis></term> 0146 <listitem><para>Sets the visibility of the folding markers pane.</para></listitem> 0147 </varlistentry> 0148 0149 <varlistentry> 0150 <term><cmdsynopsis><command>set-line-numbers</command><arg choice="req">BOOLEAN enable</arg></cmdsynopsis></term> 0151 <listitem><para>Sets the visibility of the line numbers pane.</para></listitem> 0152 </varlistentry> 0153 0154 <varlistentry> 0155 <term><cmdsynopsis><command>set-replace-tabs</command><arg choice="req">BOOLEAN enable</arg></cmdsynopsis></term> 0156 <listitem><para>If enabled, tabs are replaced with spaces as you type. 0157 </para></listitem> 0158 </varlistentry> 0159 0160 <varlistentry> 0161 <term><cmdsynopsis><command>set-remove-trailing-space</command><arg choice="req">BOOLEAN enable</arg></cmdsynopsis></term> 0162 <listitem><para>If enabled, trailing whitespace is removed whenever the cursor 0163 leaves a line.</para></listitem> 0164 </varlistentry> 0165 0166 <varlistentry> 0167 <term><cmdsynopsis><command>set-show-tabs</command><arg choice="req">BOOLEAN enable</arg></cmdsynopsis></term> 0168 <listitem><para>If enabled, TAB characters and trailing whitespace will be 0169 visualized by a small dot.</para></listitem> 0170 </varlistentry> 0171 0172 <varlistentry> 0173 <term><cmdsynopsis><command>set-show-indent</command><arg choice="req">BOOLEAN enable</arg></cmdsynopsis></term> 0174 <listitem><para>If enabled, indentation will be visualized by a vertical dotted 0175 line.</para></listitem> 0176 </varlistentry> 0177 0178 <varlistentry> 0179 <term><cmdsynopsis><command>set-indent-spaces</command><arg choice="req">BOOLEAN enable</arg></cmdsynopsis></term> 0180 <listitem><para>If enabled, the editor will indent with 0181 <option>indent-width</option> spaces for each indentation level, rather than 0182 with one TAB character.</para></listitem> 0183 </varlistentry> 0184 0185 <varlistentry> 0186 <term><cmdsynopsis><command>set-mixed-indent</command><arg choice="req">BOOLEAN enable</arg></cmdsynopsis></term> 0187 <listitem><para>If enabled, &kappname; will use a mix of TAB and spaces for 0188 indentation. Each indentation level will be <option>indent-width</option> wide, 0189 and more indentation levels will be optimized to use as many TAB characters as 0190 possible.</para> 0191 <para>When executed, this command will additionally set space indentation enabled, 0192 and if the indent width is unspecified it will be set to half of the 0193 <option>tab-width</option> for the document at the time of execution.</para></listitem> 0194 </varlistentry> 0195 0196 <varlistentry> 0197 <term><cmdsynopsis><command>set-word-wrap</command><arg choice="req">BOOLEAN 0198 enable</arg></cmdsynopsis></term> 0199 <listitem><para>Enables dynamic word wrap according to 0200 <userinput>enable</userinput>.</para></listitem> 0201 </varlistentry> 0202 0203 <varlistentry> 0204 <term><cmdsynopsis><command>set-replace-tabs-save</command><arg choice="req">BOOLEAN enable 0205 </arg></cmdsynopsis></term> 0206 <listitem><para>When enabled, tabs will be replaced with whitespace whenever 0207 the document is saved.</para></listitem> 0208 </varlistentry> 0209 0210 <varlistentry> 0211 <term><cmdsynopsis><command>set-remove-trailing-space-save</command><arg choice="req">BOOLEAN enable</arg></cmdsynopsis></term> 0212 <listitem><para>When enabled, trailing space will be removed from each line 0213 whenever the document is saved.</para></listitem> 0214 </varlistentry> 0215 0216 <varlistentry> 0217 <term><cmdsynopsis><command>set-indent-mode</command><arg choice="req">STRING name</arg></cmdsynopsis></term> 0218 <listitem><para>Sets the autoindentation mode to <userinput>name</userinput>. 0219 If <userinput>name</userinput> is not known, the mode is set to 'none'. Valid 0220 modes are 'none', 'normal', 'cstyle', 'haskell', 'lilypond', 'lisp', 'python', 0221 'ruby' and 'xml'.</para></listitem> 0222 </varlistentry> 0223 0224 <varlistentry> 0225 <term><cmdsynopsis><command>set-auto-ident</command><arg choice="req">BOOLEAN script</arg></cmdsynopsis></term> 0226 <listitem><para>Enable or disable autoindentation.</para></listitem> 0227 </varlistentry> 0228 0229 <varlistentry> 0230 <term><cmdsynopsis><command>set-highlight</command><arg choice="req">STRING highlight</arg></cmdsynopsis></term> 0231 <listitem><para>Sets the syntax highlighting system for the document. The 0232 argument must be a valid highlight name, as seen in the 0233 <menuchoice><guimenu>Tools</guimenu><guisubmenu>Highlighting</guisubmenu></menuchoice> 0234 menu. This command provides an autocompletion list for its 0235 argument.</para></listitem> 0236 </varlistentry> 0237 0238 <varlistentry> 0239 <term><cmdsynopsis><command>reload-scripts</command></cmdsynopsis></term> 0240 <listitem><para>Reload all <link linkend="dev-scripting">&javascript; 0241 scripts</link> used by &kate;, including indenters and command line scripts.</para></listitem> 0242 </varlistentry> 0243 0244 <varlistentry> 0245 <term><cmdsynopsis><command>set-mode</command><arg choice="req">STRING mode</arg></cmdsynopsis></term> 0246 <listitem><para>Choose the filetype scheme for the current document. 0247 </para></listitem> 0248 </varlistentry> 0249 0250 <varlistentry> 0251 <term><cmdsynopsis><command>nn[oremap]</command><arg choice="req">STRING original</arg> 0252 <arg choice="req">STRING mapped</arg></cmdsynopsis></term> 0253 <listitem><para>Map the key sequence <userinput>original</userinput> to 0254 <userinput>mapped</userinput>.</para></listitem> 0255 </varlistentry> 0256 0257 </variablelist> 0258 0259 </sect3> 0260 0261 <sect3 id="advanced-editing-tools-commandline-commands-edit"> 0262 <title>Commands for editing</title> 0263 0264 <para>These commands modify the current document.</para> 0265 0266 <variablelist> 0267 <varlistentry> 0268 <term><cmdsynopsis><command>indent</command></cmdsynopsis></term> 0269 <listitem><para>Indents the selected lines or the current line.</para></listitem> 0270 </varlistentry> 0271 0272 <varlistentry> 0273 <term><cmdsynopsis><command>unindent</command></cmdsynopsis></term> 0274 <listitem><para>Unindents the selected lines or current line.</para></listitem> 0275 </varlistentry> 0276 0277 <varlistentry> 0278 <term><cmdsynopsis><command>cleanindent</command></cmdsynopsis></term> 0279 <listitem><para>Cleans up the indentation of the selected lines or current line 0280 according to the indentation settings in the document. 0281 </para></listitem> 0282 </varlistentry> 0283 0284 <varlistentry> 0285 <term><cmdsynopsis><command>comment</command></cmdsynopsis></term> 0286 <listitem><para>Inserts comment markers to make the selection or selected lines 0287 or current line a comment according to the text format as defined by the syntax 0288 highlight definition for the document.</para></listitem> 0289 </varlistentry> 0290 0291 <varlistentry> 0292 <term><cmdsynopsis><command>uncomment</command></cmdsynopsis></term> 0293 <listitem><para>Removes comment markers from the selection or selected lines 0294 or current line according to the text format as defined by the syntax highlight 0295 definition for the document.</para></listitem> 0296 </varlistentry> 0297 0298 <varlistentry> 0299 <term><cmdsynopsis><command>kill-line</command></cmdsynopsis></term> 0300 <listitem><para>Deletes the current line.</para></listitem> 0301 </varlistentry> 0302 0303 <varlistentry> 0304 <term><cmdsynopsis><command>replace</command><arg choice="req"> STRING pattern</arg> 0305 <arg choice="req">STRING replacement</arg></cmdsynopsis></term> 0306 <listitem><para>Replaces text matching <userinput>pattern</userinput> with 0307 <userinput>replacement</userinput>. If you want to include whitespace in the 0308 <userinput>pattern</userinput>, you must quote both the <userinput>pattern</userinput> 0309 and <userinput>replacement</userinput> with single or double quotes. If the 0310 arguments are unquoted, the first word is used as <userinput>pattern</userinput> 0311 and the rest for <userinput>replacement</userinput>. If 0312 <userinput>replacement</userinput> is empty, each occurrence of 0313 <userinput>pattern</userinput> is removed.</para> 0314 <para>You can set flags to configure the search by adding a colon, followed 0315 by one or more letters each representing a configuration, giving the form 0316 <userinput>replace:options pattern replacement</userinput>. Available options 0317 are: 0318 0319 <variablelist> 0320 0321 <varlistentry> 0322 <term><userinput>b</userinput></term> 0323 <listitem><para>Search backwards.</para></listitem> 0324 </varlistentry> 0325 0326 <varlistentry> 0327 <term><userinput>c</userinput></term> 0328 <listitem><para>Search from cursor position.</para></listitem> 0329 </varlistentry> 0330 0331 <varlistentry> 0332 <term><userinput>e</userinput></term> 0333 <listitem><para>Search in the selection only.</para></listitem> 0334 </varlistentry> 0335 0336 <varlistentry> 0337 <term><userinput>r</userinput></term> 0338 <listitem><para>Do regular expression search. If set, you may use 0339 <userinput>\N</userinput> where N is a number to represent captures in the 0340 replacement string.</para></listitem> 0341 </varlistentry> 0342 0343 <varlistentry> 0344 <term><userinput>s</userinput></term> 0345 <listitem><para>Do case sensitive search.</para></listitem> 0346 </varlistentry> 0347 0348 <varlistentry> 0349 <term><userinput>p</userinput></term> 0350 <listitem><para>Prompt for permission to replace the next occurrence.</para></listitem> 0351 </varlistentry> 0352 0353 <varlistentry> 0354 <term><userinput>w</userinput></term> 0355 <listitem><para>Match whole words only.</para></listitem> 0356 </varlistentry> 0357 0358 </variablelist> 0359 0360 </para> 0361 </listitem> 0362 </varlistentry> 0363 0364 <varlistentry> 0365 <term><cmdsynopsis><command>date</command><arg choice="req">STRING format</arg></cmdsynopsis></term> 0366 <listitem><para>Inserts a date/time string as defined by the specified 0367 <userinput>format</userinput>, or the format <quote>yyyy-MM-dd hh:mm:ss</quote> 0368 if none is specified. The following translations are done when interpreting 0369 <userinput>format</userinput>: 0370 0371 <informaltable> 0372 <tgroup cols="2"> 0373 <tbody> 0374 <row><entry><literal>d</literal></entry><entry>The day as number without a leading zero (1-31).</entry></row> 0375 <row><entry><literal>dd</literal></entry><entry>The day as number with a leading zero (01-31).</entry></row> 0376 <row><entry><literal>ddd</literal></entry><entry>The abbreviated localized day name (⪚ 'Mon'..'Sun').</entry></row> 0377 <row><entry><literal>dddd</literal></entry><entry>The long localized day name (⪚ 'Monday'..'Sunday').</entry></row> 0378 <row><entry><literal>M</literal></entry><entry>The month as number without a leading zero (1-12).</entry></row> 0379 <row><entry><literal>MM</literal></entry><entry>The month as number with a leading zero (01-12).</entry></row> 0380 <row><entry><literal>MMMM</literal></entry><entry>The long localized month name (⪚ 'January'..'December').</entry></row> 0381 <row><entry><literal>MMM</literal></entry><entry>The abbreviated localized month name (⪚ 'Jan'..'Dec').</entry></row> 0382 <row><entry><literal>yy</literal></entry><entry>The year as two digit number 0383 (00-99).</entry></row> 0384 <row><entry><literal>yyyy</literal></entry><entry>The year as four digit number (1752-8000).</entry></row> 0385 <row><entry><literal>h</literal></entry><entry>The hour without a leading zero (0..23 or 1..12 if AM/PM display).</entry></row> 0386 <row><entry><literal>hh</literal></entry><entry>The hour with a leading zero (00..23 or 01..12 if AM/PM display).</entry></row> 0387 <row><entry><literal>m</literal></entry><entry>The minute without a leading zero (0..59).</entry></row> 0388 <row><entry><literal>mm</literal></entry><entry>The minute with a leading zero (00..59).</entry></row> 0389 <row><entry><literal>s</literal></entry><entry>The second without a leading zero (0..59).</entry></row> 0390 <row><entry><literal>ss</literal></entry><entry>The second with a leading zero (00..59).</entry></row> 0391 <row><entry><literal>z</literal></entry><entry>The milliseconds without leading zeroes (0..999).</entry></row> 0392 <row><entry><literal>zzz</literal></entry><entry>The milliseconds with leading zeroes (000..999).</entry></row> 0393 <row><entry><literal>AP</literal></entry><entry>Use AM/PM display. AP will be replaced by either "AM" or "PM".</entry></row> 0394 <row><entry><literal>ap</literal></entry><entry>Use am/pm display. ap will be replaced by either "am" or "pm".</entry></row> 0395 </tbody> 0396 </tgroup> 0397 </informaltable> 0398 0399 </para></listitem> 0400 </varlistentry> 0401 0402 <varlistentry> 0403 <term><cmdsynopsis><command>char</command><arg choice="req">STRING identifier</arg></cmdsynopsis></term> 0404 <listitem> 0405 <para>This command allows you to insert literal characters by their 0406 numerical identifier, in decimal, octal or hexadecimal form. 0407 To use it launch the Editing Command dialog and type <userinput>char: 0408 [number]</userinput> in the entry box, then hit 0409 <guibutton>OK</guibutton>.</para> 0410 0411 <example> 0412 <title><command>char</command> examples</title> 0413 0414 <para>Input: <userinput>char:234</userinput></para> 0415 <para>Output: <computeroutput>ê</computeroutput></para> 0416 <para>Input: <userinput>char:0x1234</userinput></para> 0417 <para>Output: <computeroutput>ሴ</computeroutput></para> 0418 </example> 0419 0420 </listitem> 0421 </varlistentry> 0422 0423 <varlistentry> 0424 <term> 0425 <indexterm><primary>replace, sed style</primary> 0426 <secondary>search, sed style</secondary></indexterm> 0427 <command>s///[ig]</command> <command>%s///[ig]</command></term> 0428 0429 <listitem> 0430 <para>This command does a sed-like search/replace operation on the 0431 current line, or on the whole file (<command>%s///</command>).</para> 0432 0433 <para>In short, the text is searched for text matching the 0434 <emphasis>search pattern</emphasis>, the regular expression between 0435 the first and the second slash, and when a match is found, the 0436 matching part of the text is replaced with the expression between the 0437 second and last slash. Parentheses in the search pattern 0438 create <emphasis>back references</emphasis>, that is the command 0439 remembers which part of the string matched in the parentheses; these 0440 strings can be reused in the replace pattern, referred to as 0441 <userinput>\1</userinput> for the first set of parentheses, 0442 <userinput>\2</userinput> for the second and so on.</para> 0443 0444 <para>To search for a literal <literal>(</literal> or 0445 <literal>)</literal>, you need to <emphasis>escape</emphasis> it using 0446 a backslash character: <userinput>\(\)</userinput></para> 0447 0448 <para>If you put an <userinput>i</userinput> at the end of the 0449 expression, the matching will be case insensitive. If you put a 0450 <userinput>g</userinput> at the end, all occurrences of the pattern will be 0451 replaced, otherwise only the first occurrence is replaced.</para> 0452 0453 <example> 0454 0455 <title>Replacing text in the current line</title> 0456 0457 <para>Your friendly compiler just stopped, telling you that the class 0458 <classname>myClass</classname> mentioned in line 3902 in your source file 0459 is not defined.</para> 0460 0461 <para>"Buckle!" you think, it is of course 0462 <classname>MyClass</classname>. You go to line 3902, and instead of trying 0463 to find the word in the text, you launch the Editing Command Dialog, 0464 enter <userinput>s/myclass/MyClass/i</userinput>, hit the 0465 <guibutton>OK</guibutton> button, save the file and compile – 0466 successfully without the error.</para> 0467 0468 </example> 0469 0470 <example> 0471 <title>Replacing text in the whole file</title> 0472 0473 <para>Imagine that you have a file, in which you mention a <quote>Miss 0474 Jensen</quote> several times, when someone comes in and tells you that 0475 she just got married to <quote>Mr Jones</quote>. You want, of course, 0476 to replace each and every occurrence of <quote>Miss Jensen</quote> 0477 with <quote>Ms Jones</quote>.</para> 0478 0479 <para>Enter the command line and issue the command 0480 <userinput>%s/Miss Jensen/Ms Jones/</userinput> and hit return, you 0481 are done.</para> 0482 0483 </example> 0484 0485 <example> 0486 <title>A More Advanced Example</title> 0487 0488 <para>This example makes use of <emphasis>back references</emphasis> 0489 as well as a <emphasis>character class</emphasis> (if you do not know what 0490 that is, please refer to the related documentation mentioned 0491 below).</para> 0492 0493 <para>Suppose you have the following line: 0494 0495 <programlisting>void MyClass::DoStringOps( String &foo, String &bar, String *p, int &a, int &b )</programlisting> 0496 </para> 0497 <para>Now you realize that this is not nice code, and decide that you 0498 want to use the <constant>const</constant> keyword for all 0499 <quote>address of</quote> arguments, those characterized by the & 0500 operator in front of the argument name. You would also like to 0501 simplify the white space, so that there is only 1 whitespace character 0502 between each word.</para> 0503 0504 <para>Launch the Editing Command Dialog, and enter: 0505 <userinput>s/\s+(\w+)\s+(&)/ const \1 \2/g</userinput> and hit the 0506 <guibutton>OK</guibutton> button. The <userinput>g</userinput> at the end of the expression makes 0507 the regular expression recompile for each match to save the <emphasis>backreferences</emphasis>.</para> 0508 0509 <para>Output: 0510 0511 <computeroutput>void MyClass::DoStringOps( const String &foo, const String &bar, String *p, const int &a, const int &b )</computeroutput></para> 0512 0513 <para>Mission completed! Now, what happened? Well, we looked for some 0514 white space (<literal>\s+</literal>) followed by one or more 0515 alphabetic characters (<literal>\w+</literal>) followed by some more 0516 whitespace (<literal>\s+</literal>) followed by an ampersand, and in 0517 the process saved the alphabetic chunk and the ampersand for reuse in 0518 the replace operation. Then we replaced the matching part of our line 0519 with one whitespace followed by <quote>const</quote> followed by one 0520 whitespace followed by our saved alphabetical chunk 0521 (<literal>\1</literal>) followed by one whitespace followed by our 0522 saved ampersand (<literal>\2</literal>)</para> 0523 0524 <para>Now in some cases the alphabetical chunk was 0525 <quote>String</quote>, in some <quote>int</quote>, so using the 0526 character class <literal>\w</literal> and the <literal>+</literal> 0527 quantifier proved a valuable asset.</para> 0528 0529 </example> 0530 0531 </listitem> 0532 0533 </varlistentry> 0534 0535 <varlistentry> 0536 <term><cmdsynopsis><command>sort</command></cmdsynopsis></term> 0537 <listitem><para>Sorts the selected text or entire document.</para></listitem> 0538 </varlistentry> 0539 0540 <varlistentry> 0541 <term><cmdsynopsis><command>natsort</command></cmdsynopsis></term> 0542 <listitem><para>Sort the selected lines or entire document naturally.</para> 0543 0544 <example> 0545 <title><command>sort</command> vs. <command>natsort</command></title> 0546 <para><userinput><command>sort</command>(a10, a1, a2)</userinput> results in 0547 <computeroutput>a1, a10, a2</computeroutput></para> 0548 <para><userinput><command>natsort</command>(a10, a1, a2)</userinput> results in 0549 <computeroutput>a1, a2, a10</computeroutput></para> 0550 </example></listitem> 0551 </varlistentry> 0552 0553 <varlistentry> 0554 <term><cmdsynopsis><command>moveLinesDown</command></cmdsynopsis></term> 0555 <listitem><para>Move selected lines down.</para></listitem> 0556 </varlistentry> 0557 0558 <varlistentry> 0559 <term><cmdsynopsis><command>moveLinesUp</command></cmdsynopsis></term> 0560 <listitem><para>Move selected lines up.</para></listitem> 0561 </varlistentry> 0562 0563 <varlistentry> 0564 <term><cmdsynopsis><command>uniq</command></cmdsynopsis></term> 0565 <listitem><para>Remove duplicated lines from the selected text or the whole 0566 document.</para></listitem> 0567 </varlistentry> 0568 0569 <varlistentry> 0570 <term><cmdsynopsis><command>rtrim</command></cmdsynopsis></term> 0571 <listitem><para>Remove trailing space from the selected text or the whole 0572 document.</para></listitem> 0573 </varlistentry> 0574 0575 <varlistentry> 0576 <term><cmdsynopsis><command>ltrim</command></cmdsynopsis></term> 0577 <listitem><para>Remove leading space from the selected text or the whole 0578 document.</para></listitem> 0579 </varlistentry> 0580 0581 <varlistentry> 0582 <term><cmdsynopsis><command>join</command><arg choice="opt">STRING separator</arg></cmdsynopsis></term> 0583 <listitem><para>Join selected lines or whole document. Optionally takes a parameter 0584 defining a separator, for example: <userinput><command>join</command> ', '</userinput> 0585 </para></listitem> 0586 </varlistentry> 0587 0588 <varlistentry> 0589 <term><cmdsynopsis><command>rmblank</command></cmdsynopsis></term> 0590 <listitem><para>Remove all blank spaces from the selected text or the whole 0591 document.</para></listitem> 0592 </varlistentry> 0593 0594 <varlistentry> 0595 <term><cmdsynopsis><command>alignon</command></cmdsynopsis></term> 0596 <listitem> 0597 <para>This command aligns lines in the selected block or whole document on the column given by a regular expression given as an argument.</para> 0598 <para>If you give an empty pattern it will align on the first non-blank character by default.</para> 0599 <para>If the pattern has a capture it will indent on the captured match.</para> 0600 <para><emphasis>Examples:</emphasis></para> 0601 <para><userinput>alignon -</userinput> will insert spaces before the first '-' of each lines to align them all on the same column.</para> 0602 <para><userinput>alignon :\\s+(.)</userinput> will insert spaces before the first non-blank character that occurs after a colon to align them all on the same column.</para> 0603 </listitem> 0604 </varlistentry> 0605 0606 <varlistentry> 0607 <term><cmdsynopsis><command>unwrap</command></cmdsynopsis></term> 0608 <listitem><para>Unwrap the selected text or the whole document.</para></listitem> 0609 </varlistentry> 0610 0611 <varlistentry> 0612 <term><cmdsynopsis><command>each</command><arg choice="req">STRING script</arg></cmdsynopsis></term> 0613 <listitem><para>Given a &javascript; function as an argument, call that for the list of 0614 selected lines and replace them with the return value of that callback.</para> 0615 0616 <example> 0617 <title>Join selected lines</title> 0618 <para><userinput><command>each</command> 'function(lines){return lines.join(", ")}' 0619 </userinput></para> 0620 0621 <para>Or, more briefly:</para> 0622 <para><userinput><command>each</command> 'lines.join(", ")'</userinput></para> 0623 </example> 0624 0625 </listitem> 0626 </varlistentry> 0627 0628 0629 0630 <varlistentry> 0631 <term><cmdsynopsis><command>filter</command><arg choice="req">STRING script</arg></cmdsynopsis></term> 0632 <listitem><para>Given a &javascript; function as an argument, call that for the list of 0633 selected lines and remove those where the callback returns false.</para> 0634 0635 <example> 0636 <title>Remove blank lines</title> 0637 <para><userinput><command>filter</command> 'function(1){return 1.length > 0;}' 0638 </userinput></para> 0639 0640 <para>Or, more briefly:</para> 0641 <para><userinput><command>filter</command> 'line.length > 0'</userinput></para> 0642 </example> 0643 0644 </listitem> 0645 </varlistentry> 0646 0647 <varlistentry> 0648 <term><cmdsynopsis><command>map</command><arg choice="req">STRING script</arg></cmdsynopsis></term> 0649 <listitem><para>Given a &javascript; function as an argument, call that for the list of 0650 selected lines and replace the line with the value of the callback.</para> 0651 0652 <example> 0653 <title>Remove blank lines</title> 0654 <para><userinput><command>map</command> 'function(line){return 0655 line.replace(/^s+/,"");}' 0656 </userinput></para> 0657 0658 <para>Or, more briefly:</para> 0659 <para><userinput><command>map</command> 'line.replace(/^s+/,"")'</userinput></para> 0660 </example> 0661 0662 </listitem> 0663 </varlistentry> 0664 0665 <varlistentry> 0666 <term><cmdsynopsis><command>duplicateLinesUp</command></cmdsynopsis></term> 0667 <listitem><para>Duplicate the selected lines above the current selection.</para> 0668 </listitem> 0669 </varlistentry> 0670 0671 <varlistentry> 0672 <term><cmdsynopsis><command>duplicateLinesDown</command></cmdsynopsis></term> 0673 <listitem><para>Duplicate the selected lines below the current selection.</para> 0674 </listitem> 0675 </varlistentry> 0676 0677 </variablelist> 0678 0679 </sect3> 0680 0681 <sect3 id="advanced-editing-tools-commandline-commands-navigation"> 0682 <title>Commands for navigation</title> 0683 0684 <variablelist> 0685 0686 <varlistentry> 0687 <term><cmdsynopsis><command>goto</command><arg choice="req">INT line</arg></cmdsynopsis></term> 0688 <listitem><para>This command navigates to the specified line.</para></listitem> 0689 </varlistentry> 0690 0691 <varlistentry> 0692 <term><cmdsynopsis><command>grep</command> <arg choice="req">STRING pattern</arg> 0693 </cmdsynopsis></term> 0694 <listitem><para>Search the document for the regular expression 0695 <userinput>pattern</userinput>. For more information, see 0696 <xref linkend="regular-expressions" />.</para> 0697 </listitem> 0698 </varlistentry> 0699 0700 <varlistentry> 0701 <term><cmdsynopsis><command>find</command><arg choice="req">STRING pattern</arg></cmdsynopsis></term> 0702 <listitem><para>This command navigates to the first occurrence of 0703 <userinput>pattern</userinput> according to the configuration. Following 0704 occurrences can be found using 0705 <menuchoice><guimenu>Edit</guimenu><guimenuitem>Find Next</guimenuitem></menuchoice> 0706 (the default shortcut is <keycap>F3</keycap>).</para> 0707 <para>The find command can be configured by appending a colon followed by one or 0708 more options, the form is 0709 <userinput>find:options pattern</userinput>. The 0710 following options are supported:</para> 0711 0712 <variablelist> 0713 0714 <varlistentry> 0715 <term><userinput>b</userinput></term> 0716 <listitem><para>Search backwards.</para></listitem> 0717 </varlistentry> 0718 0719 <varlistentry> 0720 <term><userinput>c</userinput></term> 0721 <listitem><para>Search from cursor position.</para></listitem> 0722 </varlistentry> 0723 0724 <varlistentry> 0725 <term><userinput>e</userinput></term> 0726 <listitem><para>Search in the selection only.</para></listitem> 0727 </varlistentry> 0728 0729 <varlistentry> 0730 <term><userinput>r</userinput></term> 0731 <listitem><para>Do regular expression search. If set, you may use 0732 <userinput>\N</userinput> where N is a number to represent captures in the 0733 replacement string.</para></listitem> 0734 </varlistentry> 0735 0736 <varlistentry> 0737 <term><userinput>s</userinput></term> 0738 <listitem><para>Do case sensitive search.</para></listitem> 0739 </varlistentry> 0740 0741 <varlistentry> 0742 <term><userinput>w</userinput></term> 0743 <listitem><para>Match whole words only.</para></listitem> 0744 </varlistentry> 0745 0746 </variablelist> 0747 </listitem> 0748 0749 </varlistentry> 0750 0751 <varlistentry> 0752 <term><cmdsynopsis><command>ifind</command><arg choice="req">STRING pattern</arg></cmdsynopsis></term> 0753 <listitem><para>This command provides <quote>as-you-type</quote> searching. You 0754 can configure the behavior of the search by appending a colon 0755 followed by one or more options, like this: 0756 <userinput>ifind:options pattern</userinput>. Allowed options are: 0757 0758 <variablelist> 0759 <varlistentry> 0760 <term><userinput>b</userinput></term> 0761 <listitem><para>Search backwards.</para></listitem> 0762 </varlistentry> 0763 0764 <varlistentry> 0765 <term><userinput>r</userinput></term> 0766 <listitem><para>Do regular expression search.</para></listitem> 0767 </varlistentry> 0768 0769 <varlistentry> 0770 <term><userinput>s</userinput></term> 0771 <listitem><para>Do case sensitive search.</para></listitem> 0772 </varlistentry> 0773 0774 <varlistentry> 0775 <term><userinput>c</userinput></term> 0776 <listitem><para>Search from cursor position.</para></listitem> 0777 </varlistentry> 0778 0779 </variablelist> 0780 </para></listitem> 0781 </varlistentry> 0782 0783 </variablelist> 0784 0785 </sect3> 0786 0787 0788 <sect3 id="advanced-editing-tools-commandline-commands-basic"> 0789 <title>Commands for Basic Editor Functions (These depend on the application the editor component is used in)</title> 0790 0791 <variablelist> 0792 0793 <varlistentry> 0794 <term><cmdsynopsis><command>w</command></cmdsynopsis></term> 0795 <listitem><para>Save the current document.</para></listitem> 0796 </varlistentry> 0797 0798 <varlistentry> 0799 <term><cmdsynopsis><command>wa</command></cmdsynopsis></term> 0800 <listitem><para>Save all currently open documents.</para></listitem> 0801 </varlistentry> 0802 0803 <varlistentry> 0804 <term><cmdsynopsis><command>q</command></cmdsynopsis></term> 0805 <listitem><para>Close the current document.</para></listitem> 0806 </varlistentry> 0807 0808 <varlistentry> 0809 <term><cmdsynopsis><command>qa</command></cmdsynopsis></term> 0810 <listitem><para>Close all open documents.</para></listitem> 0811 </varlistentry> 0812 0813 <varlistentry> 0814 <term><cmdsynopsis><command>wq</command></cmdsynopsis></term> 0815 <listitem><para>Save and close the current document.</para></listitem> 0816 </varlistentry> 0817 0818 <varlistentry> 0819 <term><cmdsynopsis><command>wqa</command></cmdsynopsis></term> 0820 <listitem><para>Save and close all currently open documents.</para></listitem> 0821 </varlistentry> 0822 0823 <varlistentry> 0824 <term><cmdsynopsis><command>x</command></cmdsynopsis></term> 0825 <listitem><para>Save and close the current document only if it has changed. 0826 </para></listitem> 0827 </varlistentry> 0828 0829 <varlistentry> 0830 <term><cmdsynopsis><command>x</command></cmdsynopsis></term> 0831 <listitem><para>Save and close all currently open documents only if they have 0832 changed.</para></listitem> 0833 </varlistentry> 0834 0835 <varlistentry> 0836 <term><cmdsynopsis><command>bp</command></cmdsynopsis></term> 0837 <listitem><para>Go to the previous document in the documents list. 0838 </para></listitem> 0839 </varlistentry> 0840 0841 <varlistentry> 0842 <term><cmdsynopsis><command>bn</command></cmdsynopsis></term> 0843 <listitem><para>Go to the next document in the documents list. 0844 </para></listitem> 0845 </varlistentry> 0846 0847 <varlistentry> 0848 <term><cmdsynopsis><command>new</command></cmdsynopsis></term> 0849 <listitem><para>Open a new document in horizontal split view. 0850 </para></listitem> 0851 </varlistentry> 0852 0853 <varlistentry> 0854 <term><cmdsynopsis><command>vnew</command></cmdsynopsis></term> 0855 <listitem><para>Open a new document in vertical split view. 0856 </para></listitem> 0857 </varlistentry> 0858 0859 <varlistentry> 0860 <term><cmdsynopsis><command>e</command></cmdsynopsis></term> 0861 <listitem><para>Reload the current document if it has changed on disk. 0862 </para></listitem> 0863 </varlistentry> 0864 0865 <varlistentry> 0866 <term><cmdsynopsis><command>enew</command></cmdsynopsis></term> 0867 <listitem><para>Edit a new document. 0868 </para></listitem> 0869 </varlistentry> 0870 0871 <varlistentry> 0872 <term><cmdsynopsis><command>print</command></cmdsynopsis></term> 0873 <listitem><para>Open the Print dialog to print the current document. 0874 </para></listitem> 0875 </varlistentry> 0876 0877 </variablelist> 0878 0879 </sect3> 0880 0881 0882 </sect2> 0883 0884 </sect1> 0885 0886 <sect1 id="advanced-editing-tools-code-folding"> 0887 <title>Using Code Folding</title> 0888 0889 <para>Code folding allows you to hide parts of a document in the editor, making 0890 it easier to overview large documents. In &kappname; the foldable regions are 0891 calculated using rules defined in the syntax highlight definitions, and 0892 therefore it is only available in some formats - typically program source code, 0893 XML markup and similar. Most highlight definitions supporting code folding 0894 also lets you manually define foldable regions, typically using the 0895 <userinput>BEGIN</userinput> and <userinput>END</userinput> keywords.</para> 0896 0897 <para>To use the code folding feature, activate the folding markers using 0898 <menuchoice><guimenu>View</guimenu><guimenuitem>Show Folding 0899 Markers</guimenuitem></menuchoice> menu item if they are not already visible. 0900 The Folding Markers Pane on the left side of the screen displays a graphical 0901 view of the foldable regions, with triangle symbols to indicate the possible operation 0902 on a given region: a top down triangle means that the region is expanded, clicking it will 0903 collapse the region and a right pointing triangle will be displayed instead.</para> 0904 <!--FIXME change Three to Four when Unfold Toplevel Nodes action is back--> 0905 <para>Three commands are provided to manipulate the state of folding regions, 0906 see the <link linkend="view-code-folding">menu documentation</link>. 0907 </para> 0908 0909 <para>The folded lines are remembered when a file is closed, so when you reopen 0910 the file the folded nodes will still be folded. This applies to reload operations 0911 as well.</para> 0912 0913 <para>If you do not want to use the code folding feature, you can disable 0914 the <guilabel>Show folding markers (if available)</guilabel> option in the 0915 <link linkend="appearance">Appearance</link> page of the editor 0916 configuration.</para> 0917 0918 </sect1> 0919 0920 </chapter>