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

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

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