PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/doc/users-guide/source-edit.xml

#
XML | 598 lines | 586 code | 4 blank | 8 comment | 0 complexity | 242b8b80d29bd01440b150988335efb0 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
  1. <!-- jEdit buffer-local properties: -->
  2. <!-- :tabSize=1:indentSize=1:noTabs=true:wrap=soft:maxLineLen=80: -->
  3. <!-- :xml.root=users-guide.xml: -->
  4. <chapter id="source-edit"><title>Editing Source Code</title>
  5. <sect1 id="modes"><title>Edit Modes</title>
  6. <para>
  7. An <firstterm>edit mode</firstterm> specifies syntax highlighting
  8. rules, auto indent behavior, and various other customizations for editing
  9. a certain file type. This section
  10. only covers using existing edit modes; information about writing your
  11. own can be found in <xref linkend="writing-modes-part" />.
  12. </para>
  13. <para>
  14. When a file is opened, jEdit first checks the file name against a list
  15. of known patterns. For example, files whose names end with <filename>.c</filename>
  16. are opened with C mode, and files named <filename>Makefile</filename> are
  17. opened with Makefile mode. If a suitable match based on file name cannot be
  18. found, jEdit checks the first line of the file. For example, files whose
  19. first line is <filename>#!/bin/sh</filename> are opened with shell script mode.
  20. </para>
  21. <sect2 id="mode-selection"><title>Mode Selection</title>
  22. <para>
  23. File name and first line matching is done using glob patterns similar to those used in Unix shells. Glob patterns associated with edit modes can be changed in the
  24. <guibutton>Editing</guibutton> pane of the
  25. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global Options</guimenuitem>
  26. dialog box. Note that the glob patterns must match the file name or first line exactly; so to match files whose first line contains <literal>begin</literal>, you must use a first line glob of <literal>*begin*</literal>.
  27. See <xref linkend="globs"/> for a description of glob pattern syntax.
  28. </para>
  29. <para>
  30. The default edit mode for files which do not match any pattern can be set in the <guibutton>Editing</guibutton> pane as well.
  31. </para>
  32. <para>
  33. The edit mode can be specified manually as well. The current buffer's edit
  34. mode can be set on a one-time basis in the
  35. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Buffer Options</guimenuitem>
  36. dialog box; see <xref linkend="buffer-opts" />. To set a buffer's edit mode
  37. for future editing sessions,
  38. place the following in one of the first or last 10 lines of the buffer,
  39. where <replaceable>edit mode</replaceable> is the name of the desired edit
  40. mode:
  41. </para>
  42. <screen>:mode=<replaceable>edit mode</replaceable>:</screen>
  43. </sect2>
  44. <sect2 id="syntax-hilite"><title>Syntax Highlighting</title>
  45. <para>
  46. Syntax highlighting is the display of programming language
  47. tokens using different fonts and colors. This makes code
  48. easier to follow and errors such as misplaced quotes easier to spot.
  49. All edit modes except for
  50. the plain text mode perform some kind of syntax highlighting.
  51. </para>
  52. <para>
  53. The colors and styles used to highlight syntax tokens can be changed
  54. in the <guibutton>Syntax Highlighting</guibutton> pane of the
  55. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global Options</guimenuitem>
  56. dialog box; see <xref linkend="syntax-hilite-pane" />.
  57. </para>
  58. </sect2>
  59. </sect1>
  60. <sect1 id="indent"><title>Tabbing and Indentation</title>
  61. <para>
  62. jEdit makes a distinction between the <firstterm>tab width</firstterm>,
  63. which is is used when displaying hard tab characters, and the <firstterm>indent
  64. width</firstterm>, which is used when a level of indent is to be added or
  65. removed, for example by mode-specific auto indent routines. Both can be
  66. changed in one of several ways:
  67. </para>
  68. <itemizedlist>
  69. <listitem><para>On a global or mode-specific basis in the
  70. <guibutton>Editing</guibutton> pane
  71. of the the <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global
  72. Options</guimenuitem> dialog box. See <xref linkend="editing-pane"/>.
  73. </para></listitem>
  74. <listitem><para>In the current buffer
  75. for the duration of the editing session in the
  76. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Buffer Options</guimenuitem>
  77. dialog box. See <xref linkend="buffer-opts"/>.</para></listitem>
  78. <listitem><para>In the current buffer
  79. for future editing sessions by placing the
  80. following in one of the first or last 10 lines of the buffer, where
  81. <replaceable>n</replaceable> is the desired tab width, and
  82. <replaceable>m</replaceable> is the desired indent width:
  83. </para>
  84. <screen>:tabSize=<replaceable>n</replaceable>:indentSize=<replaceable>m</replaceable>:</screen>
  85. </listitem>
  86. </itemizedlist>
  87. <para>
  88. <guimenu>Edit</guimenu>&gt;<guisubmenu>Indent</guisubmenu>&gt;<guisubmenu>Shift
  89. Indent Left</guisubmenu>
  90. (shortcut: <keycap>S+TAB</keycap> or <keycap>A+LEFT</keycap>)
  91. adds one level of indent to each selected line, or the current line
  92. if there is no selection.
  93. </para>
  94. <para>
  95. <guimenu>Edit</guimenu>&gt;<guisubmenu>Indent</guisubmenu>&gt;<guisubmenu>Shift
  96. Indent Right</guisubmenu>
  97. (shortcut: <keycap>A+RIGHT</keycap>)
  98. removes one level of indent from each selected line, or the current line
  99. if there is no selection. Pressing <keycap>Tab</keycap> while a multi-line
  100. selection is active has the same effect.
  101. </para>
  102. <para>
  103. <guimenu>Edit</guimenu>&gt;<guisubmenu>Indent</guisubmenu>&gt;<guimenuitem>Remove
  104. Trailing Whitespace</guimenuitem>
  105. (shortcut: <keycap>C+e r</keycap>) removes all whitespace from the end of each selected line, or
  106. the current line if there is no selection.
  107. </para>
  108. <sect2 id="soft-tabs"><title>Soft Tabs</title>
  109. <para>
  110. Files containing hard tab characters may look less than ideal if
  111. the default tab size is changed, so some people prefer using
  112. multiple space characters instead of hard tabs to indent code.
  113. </para>
  114. <para>
  115. This feature is known as <firstterm>soft tabs</firstterm>.
  116. Soft tabs can be enabled or disabled in one of several ways:
  117. </para>
  118. <itemizedlist>
  119. <listitem><para>On a global or mode-specific basis in the
  120. <guibutton>Editing</guibutton> pane of the
  121. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global
  122. Options</guimenuitem> dialog box. See <xref linkend="editing-pane"/>.</para></listitem>
  123. <listitem><para>In the current buffer for
  124. the duration of the editing session in the
  125. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Buffer Options</guimenuitem>
  126. dialog box. See <xref linkend="buffer-opts"/>.</para></listitem>
  127. <listitem><para>In the current buffer for
  128. future editing sessions by placing the following in one of the first
  129. or last 10 lines of the buffer, where <replaceable>flag</replaceable> is either
  130. <quote>true</quote> or <quote>false</quote>:
  131. </para>
  132. <screen>:noTabs=<replaceable>flag</replaceable>:</screen>
  133. </listitem>
  134. </itemizedlist>
  135. <para>
  136. Changing the soft tabs setting has no effect on existing tab characters;
  137. it only affects subsequently-inserted tabs.
  138. </para>
  139. <para>
  140. <guimenu>Edit</guimenu>&gt;<guisubmenu>Indent</guisubmenu>&gt;<guimenuitem>Spaces
  141. to Tabs</guimenuitem>
  142. converts soft tabs to hard tabs in the current selection, or the entire
  143. buffer if nothing is selected.
  144. </para>
  145. <para>
  146. <guimenu>Edit</guimenu>&gt;<guisubmenu>Indent</guisubmenu>&gt;<guimenuitem>Tabs
  147. to Spaces</guimenuitem>
  148. converts hard tabs to soft tabs in the current selection, or the entire
  149. buffer if nothing is selected.
  150. </para>
  151. </sect2>
  152. <sect2 id="autoindent"><title>Automatic Indent</title>
  153. <para>
  154. The auto indent feature inserts the appropriate number of tabs or
  155. spaces at the beginning of a line by looking at program structure.
  156. </para>
  157. <para>
  158. In the default configuration, pressing <keycap>ENTER</keycap>
  159. will create a new line with the appropriate amount of
  160. indent automatically, and pressing
  161. <keycap>TAB</keycap> at the beginning of, or inside the leading
  162. whitespace of a line will insert the appropriate amount of
  163. indentation. Pressing it again will insert a tab character.
  164. </para>
  165. <para>
  166. The behavior of the <keycap>ENTER</keycap> and <keycap>TAB</keycap> keys can
  167. be configured in the <guibutton>Shortcuts</guibutton> pane of the
  168. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global Options</guimenuitem>
  169. dialog. box, just as with any other key. The <keycap>ENTER</keycap> key can be bound
  170. to one of the following, or indeed any other command or macro:
  171. </para>
  172. <itemizedlist>
  173. <listitem><para><guimenuitem>Insert Newline</guimenuitem>.</para></listitem>
  174. <listitem><para><guimenuitem>Insert Newline and Indent</guimenuitem>, which
  175. is the default.</para></listitem>
  176. </itemizedlist>
  177. <para>
  178. The <keycap>TAB</keycap> can be bound to one of the following, or again,
  179. any other command or macro:
  180. </para>
  181. <itemizedlist>
  182. <listitem><para><guimenuitem>Insert Tab</guimenuitem>.</para></listitem>
  183. <listitem><para><guimenuitem>Insert Tab or Indent</guimenuitem>, which is
  184. the default.</para></listitem>
  185. <listitem><para><guimenuitem>Indent Selected Lines</guimenuitem>.</para></listitem>
  186. </itemizedlist>
  187. <para>
  188. See <xref linkend="shortcuts-pane"/> for details.
  189. </para>
  190. <para>
  191. Auto indent behavior is mode-specific. In most edit modes,
  192. the indent of the previous line is simply copied over.
  193. However, in C-like languages (C, C++, Java, JavaScript), curly
  194. brackets and language statements are taken into account and indent
  195. is added and removed as necessary.
  196. </para>
  197. <para>
  198. <guimenu>Edit</guimenu>&gt;<guisubmenu>Source</guisubmenu>&gt;<guisubmenu>Indent
  199. Selected Lines</guisubmenu>
  200. (shortcut: <keycap>C+i</keycap>)
  201. indents all selected lines, or the current line if there is no
  202. selection.
  203. </para>
  204. <para>
  205. To insert a literal tab or newline without performing
  206. indentation, prefix the tab or newline with <keycap>C+e v</keycap>.
  207. For example,
  208. to create a new line without any indentation, type <keycap>C+e v ENTER</keycap>.
  209. </para>
  210. </sect2>
  211. </sect1>
  212. <sect1 id="commenting"><title>Commenting Out Code</title>
  213. <para>
  214. Most programming and markup languages support the notion of
  215. <quote>comments</quote>, or
  216. regions of code which are ignored by the compiler/interpreter. jEdit
  217. has commands which make inserting comments more convenient.
  218. </para>
  219. <para>
  220. Comment strings are mode-specific, and some in some modes such as HTML
  221. different parts of a buffer can have different comment strings.
  222. For example, in HTML files, different comment strings are used for
  223. HTML text and inline JavaScript.
  224. </para>
  225. <para>
  226. <guimenu>Edit</guimenu>&gt;<guisubmenu>Source
  227. Code</guisubmenu>&gt;<guimenuitem>Range Comment</guimenuitem>
  228. (shortcut: <keycap>C+e C+c</keycap>) encloses the
  229. selection with comment start and end strings, for example <literal>/*</literal>
  230. and <literal>*/</literal> in Java mode.
  231. </para>
  232. <para>
  233. <guimenu>Edit</guimenu>&gt;<guisubmenu>Source
  234. Code</guisubmenu>&gt;<guimenuitem>Line Comment</guimenuitem>
  235. (shortcut: <keycap>C+e C+k</keycap>) inserts the
  236. line comment string, for example <literal>//</literal> in Java mode,
  237. at the start of each selected line.
  238. </para>
  239. </sect1>
  240. <sect1 id="bracket-matching"><title>Bracket Matching</title>
  241. <para>
  242. Misplaced and unmatched brackets are one of the most common syntax
  243. errors encountered when writing code. jEdit has several features
  244. to make brackets easier to deal with.
  245. </para>
  246. <para>
  247. Positioning the caret immediately after a bracket will highlight the
  248. corresponding closing or opening bracket (assuming it is visible),
  249. and draw a scope indicator in the gutter. If the highlighted bracket is
  250. not visible, the text of the matching line will be shown in the status
  251. bar. If the matching line consists of only whitespace and the bracket
  252. itself, the <emphasis>previous line</emphasis> is shown instead. This
  253. feature is very useful when your code is indented as follows, with braces
  254. on their own lines:
  255. </para>
  256. <programlisting>public void someMethod()
  257. {
  258. if(isOK)
  259. {
  260. doSomething();
  261. }
  262. }</programlisting>
  263. <para>
  264. Invoking
  265. <guimenu>Edit</guimenu>&gt;<guisubmenu>Source</guisubmenu>&gt;<guimenuitem>Go
  266. to Matching
  267. Bracket</guimenuitem> (shortcut: <keycap>C+]</keycap>) or
  268. clicking the scope indicator in the gutter moves the caret to the
  269. matching bracket.
  270. </para>
  271. <para>
  272. <guimenu>Edit</guimenu>&gt;<guisubmenu>Source</guisubmenu>&gt;<guimenuitem>Select
  273. Code Block</guimenuitem>
  274. (shortcut: <keycap>C+[</keycap>)
  275. selects all text between the closest two brackets surrounding the caret.
  276. </para>
  277. <para>
  278. Holding down <keycap>Control</keycap> while clicking the scope indicator
  279. in the gutter or a bracket in the text area will select all text
  280. between the two matching brackets.
  281. </para>
  282. <para>
  283. <guimenu>Edit</guimenu>&gt;<guisubmenu>Source</guisubmenu>&gt;<guimenuitem>Go
  284. to Previous Bracket</guimenuitem> (shortcut: <keycap>C+e C+[</keycap>)
  285. moves the
  286. caret to the previous opening bracket.
  287. </para>
  288. <para>
  289. <guimenu>Edit</guimenu>&gt;<guisubmenu>Source</guisubmenu>&gt;<guimenuitem>Go
  290. to Next Bracket</guimenuitem> (shortcut: <keycap>C+e C+]</keycap>)
  291. moves the caret to the next closing bracket.
  292. </para>
  293. <para>
  294. Bracket highlighting in the text area and bracket scope display in the
  295. gutter can be customized in the
  296. <guibutton>Text Area</guibutton> and <guibutton>Gutter</guibutton> panes of the
  297. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global Options</guimenuitem>
  298. dialog box; see <xref linkend="global-opts" />.
  299. </para>
  300. <tip>
  301. <para>
  302. jEdit's bracket matching algorithm only checks syntax tokens with the same
  303. type as the original bracket, so for example unmatched brackets inside string
  304. literals and comments will be skipped when matching brackets that are part of
  305. program syntax.
  306. </para>
  307. </tip>
  308. </sect1>
  309. <sect1 id="abbrevs"><title>Abbreviations</title>
  310. <para>
  311. Using abbreviations reduces the time spent typing long but commonly used
  312. strings. For example, in Java mode, the abbreviation <quote>sout</quote> is
  313. defined to expand to <quote>System.out.println()</quote>, so to insert
  314. <quote>System.out.println()</quote> in a Java buffer, you only need to type
  315. <quote>sout</quote> followed by <keycap>C+;</keycap>.
  316. An abbreviation can either be global, in which case it can be used in all
  317. edit modes, or specific to a single mode.
  318. </para>
  319. <para>
  320. Abbreviations can be edited in the <guibutton>Abbreviations</guibutton> pane of the
  321. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global Options</guimenuitem>
  322. dialog box; see <xref linkend="abbrevs-pane" />. The Java, VHDL. XML and XSL edit
  323. modes include some pre-defined abbreviations you might find useful. Other
  324. modes do not have any abbreviations defined by default.
  325. </para>
  326. <para>
  327. <guimenu>Edit</guimenu>&gt;<guimenuitem>Expand Abbreviation</guimenuitem>
  328. (keyboard shortcut: <keycap>C+;</keycap>)
  329. attempts to expand the abbreviation named by the word before the caret.
  330. If no expansion could be found, it will offer to define one.
  331. </para>
  332. <para>
  333. Automatic abbreviation expansion can be enabled in the
  334. <guibutton>Abbreviations</guibutton> pane of the
  335. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global Options</guimenuitem>
  336. dialog box. If enabled, pressing the
  337. space bar after entering an
  338. abbreviation will automatically expand it.
  339. </para>
  340. <para>
  341. If automatic expansion
  342. is enabled, a space can be inserted without expanding the word before
  343. the caret by pressing
  344. <keycombo><keycap>Control</keycap><keycap>E</keycap></keycombo>
  345. <keycap>V</keycap> <keycap>Space</keycap>.
  346. </para>
  347. <sect2 id="positional-params"><title>Positional Parameters</title>
  348. <para>
  349. Positional parameters are an advanced feature that make abbreviations much
  350. more useful. The best way to describe them is with an example.
  351. </para>
  352. <para>
  353. Java mode defines an abbreviation <quote>F</quote> that is set to expand to
  354. the following:
  355. </para>
  356. <programlisting>for(int $1 = 0; $1 &lt; $2; $1++)</programlisting>
  357. <para>
  358. Expanding <literal>F#j#array.length#</literal> will insert the following
  359. text into the buffer:
  360. </para>
  361. <programlisting>for(int j = 0; j &lt; array.length; j++)</programlisting>
  362. <para>
  363. Expansions can contain up to nine positional parameters. Note that a
  364. trailing hash character (<quote>#</quote>) must be entered when expanding an
  365. abbreviation with parameters.
  366. </para>
  367. <para>
  368. If you do not specify the correct number of positional parameters when
  369. expanding an abbreviation, any missing parameters will be
  370. blank in the expansion, and extra parameters will be ignored.
  371. A status bar message will be shown stating
  372. the required number of parameters.
  373. </para>
  374. </sect2>
  375. </sect1>
  376. <sect1 id="folding"><title>Folding</title>
  377. <para>
  378. Program source code and other structured text files can be thought of
  379. as containing a hierarchy of sections, which themselves might contain sub-sections.
  380. The folding feature lets you selectively hide and show these sections,
  381. replacing hidden ones with a single line that serves as an
  382. <quote>overview</quote> of that section.
  383. Folding is disabled by default. To enable it, you must choose one of the
  384. available folding modes.
  385. </para>
  386. <para>
  387. <quote>Indent</quote>
  388. mode creates folds based on a line's leading whitespace; the more
  389. leading whitespace a block of text has, the further down it is
  390. in the hierarchy. For example:
  391. </para>
  392. <screen>This is a section
  393. This is a sub-section
  394. This is another sub-section
  395. This is a sub-sub-section
  396. Another top-level section</screen>
  397. <para>
  398. <quote>Explicit</quote> mode folds away blocks of
  399. text surrounded with <quote>{{{</quote> and <quote>}}}</quote>.
  400. For example:
  401. </para>
  402. <screen>{{{ The first line of a fold.
  403. When this fold is collapsed, only the above line will be visible.
  404. {{{ A sub-section.
  405. With text inside it.
  406. }}}
  407. {{{ Another sub-section.
  408. }}}
  409. }}}</screen>
  410. <para>
  411. Both modes have distinct advantages and disadvantages; indent folding
  412. requires no changes to be made to a buffer's text and does a decent
  413. job with most program source. Explicit folding requires <quote>fold
  414. markers</quote> to be inserted into the text, but is more flexible in
  415. exactly what to fold away.
  416. </para>
  417. <para>
  418. Some plugins might add additional folding modes; see
  419. <xref linkend="using-plugins"/> for information about plugins.
  420. </para>
  421. <para>
  422. Folding can be enabled in one of several ways:
  423. </para>
  424. <itemizedlist>
  425. <listitem><para>On a global or mode-specific
  426. basis in the <guibutton>Editing</guibutton> pane
  427. of the <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global
  428. Options</guimenuitem> dialog box. See <xref linkend="editing-pane"/>.</para></listitem>
  429. <listitem><para>In the current buffer for the duration of the editing
  430. session in the
  431. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Buffer Options</guimenuitem>
  432. dialog box. See <xref linkend="buffer-opts"/>.</para></listitem>
  433. <listitem><para>In the current buffer for future editing sessions
  434. by placing the following in the first or last 10 lines of a buffer,
  435. where <replaceable>mode</replaceable> is either <quote>indent</quote>,
  436. <quote>explicit</quote>, or the name of a plugin folding mode:
  437. </para>
  438. <screen>:folding=<replaceable>mode</replaceable>:</screen>
  439. </listitem>
  440. </itemizedlist>
  441. <warning>
  442. <para>
  443. When using indent folding, portions of the buffer may become
  444. inaccessible if you change the leading indent of the first line of a
  445. collapsed fold. If you experience this, you can use the
  446. <guimenuitem>Expand All Folds</guimenuitem> command to make the text
  447. visible again.
  448. </para>
  449. </warning>
  450. <sect2><title>Collapsing and Expanding Folds</title>
  451. <para>
  452. The first line of each fold has a triangle
  453. drawn next to it in the gutter (see <xref linkend="overview"/> for
  454. more information about the gutter). The triangle points toward the
  455. line when the fold is collapsed, and downward when the fold is
  456. expanded.
  457. Clicking the triangle collapses and
  458. expands the fold. To expand all sub-folds as well, hold down the
  459. <keycap>Shift</keycap> while clicking.
  460. </para>
  461. <para>
  462. The first line of a collapsed fold is drawn
  463. with a background color that depends on the fold level, and the number of
  464. lines in the fold is shown to the right of the line's text.
  465. </para>
  466. <para>
  467. Folds can also be collapsed and expanded using menu item commands and
  468. keyboard shortcuts.
  469. </para>
  470. <para>
  471. <guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Collapse
  472. Fold</guimenuitem> (shortcut: <keycap>A+BACK_SPACE</keycap>)
  473. collapses the fold
  474. containing the caret.
  475. </para>
  476. <para>
  477. <guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Expand
  478. Fold One Level</guimenuitem> (shortcut: <keycap>A+ENTER</keycap>)
  479. expands the
  480. fold containing the caret. Nested folds will remain collapsed,
  481. and the caret will be positioned on the first nested fold (if any).
  482. </para>
  483. <para>
  484. <guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Expand
  485. Fold Fully</guimenuitem> (shortcut: <keycap>AS+ENTER</keycap>)
  486. expands the fold
  487. containing the caret, also expanding any nested folds.
  488. </para>
  489. <para>
  490. <guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Collapse
  491. All Folds</guimenuitem> (shortcut: <keycap>C+e c</keycap>)
  492. collapses all folds in the buffer.
  493. </para>
  494. <para>
  495. <guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Expand
  496. All Folds</guimenuitem> (shortcut: <keycap>C+e x</keycap>)
  497. expands all folds in the buffer.
  498. </para>
  499. </sect2>
  500. <sect2><title>Navigating Around With Folds</title>
  501. <para>
  502. <guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Go to Parent
  503. Fold</guimenuitem> (shortcut: <keycap>C+e u</keycap>) moves
  504. the caret to the fold containing the one at the caret position.
  505. </para>
  506. <para>
  507. <guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Go to Previous
  508. Fold</guimenuitem> (shortcut: <keycap>A+UP</keycap>) moves
  509. the caret to the fold immediately before the caret position.
  510. </para>
  511. <para>
  512. <guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Go to Next
  513. Fold</guimenuitem> (shortcut: <keycap>A+DOWN</keycap>) moves
  514. the caret to the fold immediately after the caret position.
  515. </para>
  516. </sect2>
  517. <sect2><title>Miscellaneous Folding Commands</title>
  518. <para>
  519. <guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Add
  520. Explicit Fold</guimenuitem> (shortcut: <keycap>C+e a</keycap>)
  521. surrounds the
  522. selection with <quote>{{{</quote> and <quote>}}}</quote>. If the
  523. current buffer's edit mode defines comment strings (see
  524. <xref linkend="commenting" />) the explicit fold markers will
  525. automatically be commented out as well.
  526. </para>
  527. <para>
  528. <guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Select
  529. Fold</guimenuitem>
  530. (shortcut: <keycap>C+e s</keycap>)
  531. selects all lines within the fold containing the caret.
  532. <keycap>Control</keycap>-clicking a fold expansion triangle
  533. in the gutter has the same effect.
  534. </para>
  535. <para>
  536. <guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Expand
  537. Folds With Level</guimenuitem> (shortcut:
  538. <keycap>C+e ENTER <replaceable>key</replaceable></keycap>)
  539. reads the next character entered at the keyboard, and
  540. expands folds in the buffer
  541. with a fold level less than that specified, while collapsing all others.
  542. </para>
  543. <para>
  544. Sometimes it is desirable to have files open with folds initially
  545. collapsed. This can be configured as follows:
  546. </para>
  547. <itemizedlist>
  548. <listitem><para>On a global or mode-specific
  549. basis in the <guibutton>Editing</guibutton> pane
  550. of the <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global
  551. Options</guimenuitem> dialog box. See <xref linkend="editing-pane"/>.</para></listitem>
  552. <listitem><para>In the current buffer for future editing sessions
  553. by placing the following in the first or last 10 lines of a buffer,
  554. where <replaceable>level</replaceable> is the desired fold level:
  555. </para>
  556. <screen>:collapseFolds=<replaceable>level</replaceable>:</screen>
  557. </listitem>
  558. </itemizedlist>
  559. </sect2>
  560. <sect2 id="narrowing"><title>Narrowing</title>
  561. <para>
  562. The narrowing feature temporarily <quote>narrows</quote> the display
  563. of a buffer to a specified region. Text outside the region is not
  564. shown, but is still present in the buffer. <!-- Both folding and
  565. narrowing are implemented using the same code internally. -->
  566. </para>
  567. <para>
  568. Holding down <keycap>Alt</keycap> while clicking a fold expansion triangle in the gutter will hide all lines the buffer except
  569. those contained in the clicked fold.
  570. </para>
  571. <para>
  572. <guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Narrow
  573. Buffer to Fold</guimenuitem> (shortcut: <keycap>C+e n n</keycap>)
  574. hides all lines the buffer except
  575. those in the fold containing the caret.
  576. <!-- When this command is invoked, a message is shown in the
  577. status bar reminding you that you need to invoke
  578. <guimenuitem>Expand All Folds</guimenuitem> to make the rest of the buffer
  579. visible again. -->
  580. </para>
  581. <para>
  582. <guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Narrow
  583. Buffer to Selection</guimenuitem> (shortcut: <keycap>C+e n s</keycap>)
  584. hides all lines the buffer
  585. except those in the selection.
  586. </para>
  587. <para>
  588. <guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Expand
  589. All Folds</guimenuitem> (shortcut: <keycap>C+e x</keycap>)
  590. shows lines that were hidden as a result of narrowing.
  591. </para>
  592. </sect2>
  593. </sect1>
  594. </chapter>