GNU Emacs
Org
Document Structure

Document Structure

Org is an outliner. Outlines allow a document to be organized in a hierarchical structure, which, at least for me, is the best representation of notes and thoughts. An overview of this structure is achieved by folding, i.e., hiding large parts of the document to show only the general document structure and the parts currently being worked on. Org greatly simplifies the use of outlines by compressing the show and hide functionality into a single command, org-cycle, which is bound to the TAB key.

Headlines

Headlines define the structure of an outline tree. Org headlines

start on the left margin1 with one or more stars followed by a space. For example:

* First (top) level headline
** Second level
*** Third level
    some text
*** Third level
    more text
* Another first (top) level headline

The name defined in org-footnote-section is reserved. Do not use it as a title for your own headings.

Some people find the many stars too noisy and would prefer an outline that has whitespace followed by a single star as headline markers. This can be achieved using the Org Indent minor mode. See A Cleaner Outline View for more information.

Headlines are not numbered. However, you may want to dynamically number some, or all, of them. See Dynamic Headline Numbering.

An empty line after the end of a subtree is considered part of it and is hidden when the subtree is folded. However, if you leave at least two empty lines, one empty line remains visible after folding the subtree, in order to structure the collapsed view. See the variable org-cycle-separator-lines to modify this behavior.

Visibility Cycling

Global and local cycling

Outlines make it possible to hide parts of the text in the buffer. Org uses just two commands, bound to TAB and S-TAB, to change the visibility in the buffer.

TAB (org-cycle)

Subtree cycling: Rotate current subtree among the states

,-> FOLDED -> CHILDREN -> SUBTREE --.
'-----------------------------------'

Point must be on a headline for this to work(note: See, however, the option org-cycle-emulate-tab.).

S-TAB (org-global-cycle), C-u TAB

Global cycling: Rotate the entire buffer among the states

,-> OVERVIEW -> CONTENTS -> SHOW ALL --.
'--------------------------------------'

When S-TAB is called with a numeric prefix argument N, view contents only up to headlines of level N.

Note that inside tables (see Tables), S-TAB jumps to the previous field instead.

You can run global cycling using TAB only if point is at the very beginning of the buffer, but not on a headline, and org-cycle-global-at-bob is set to a non-nil value.

C-u C-u TAB (org-cycle-set-startup-visibility)

Switch back to the startup visibility of the buffer (see Initial visibility).

C-u C-u C-u TAB (org-fold-show-all)

Show all, including drawers.

C-c C-r (org-reveal)

Reveal context around point, showing the current entry, the following heading, and the hierarchy above. It is useful for working near a location that has been exposed by a sparse tree command (see Sparse Trees) or an agenda command (see Commands in the Agenda Buffer). With a prefix argument, show, on each level, all sibling headings. With a double prefix argument, also show the entire subtree of the parent.

C-c C-k (org-show-branches)

Expose all the headings of the subtree, but not their bodies.

C-c TAB (org-fold-show-children)

Expose all direct children of the subtree. With a numeric prefix argument N, expose all children down to level N.

C-c C-x b (org-tree-to-indirect-buffer)

Show the current subtree in an indirect buffer2. With a numeric prefix argument N, go up to level N and then take that tree. If N is negative, then go up that many levels. With a C-u prefix, do not remove the previously used indirect buffer.

C-c C-x v (org-copy-visible)

Copy the visible text in the region into the kill ring.

Initial visibility

When Emacs first visits an Org file, the global state is set to showeverything, i.e., all file content is visible(note: When org-agenda-inhibit-startup is non-nil, Org does not honor the default visibility state when first opening a file for the agenda (see Speeding Up Your Agendas).). This can be configured through the variable org-startup-folded, or on a per-file basis by adding one of the following lines anywhere in the buffer:

#+STARTUP: overview
#+STARTUP: content
#+STARTUP: showall
#+STARTUP: show2levels
#+STARTUP: show3levels
#+STARTUP: show4levels
#+STARTUP: show5levels
#+STARTUP: showeverything

Furthermore, any entries with a VISIBILITY property (see Properties and Columns) get their visibility adapted accordingly. Allowed values for this property are folded, children, content, and all.

C-u C-u TAB (org-cycle-set-startup-visibility)

Switch back to the startup visibility of the buffer, i.e., whatever is requested by startup options and VISIBILITY properties in individual entries.

Catching invisible edits

Sometimes you may inadvertently edit an invisible part of the buffer and be confused about what has been edited and how to undo the mistake. By default, Org prevents such edits for a limited set of user commands. Users can control which commands are affected by customizing org-fold-catch-invisible-edits-commands.

The strategy used to decide if a given edit is dangerous is controlled by org-fold-catch-invisible-edits. See the docstring of this option for the available strategies. Set the option to nil to disable catching invisible edits completely.

Motion

The following commands jump to other headlines in the buffer.

C-c C-n (org-next-visible-heading)

Next heading.

C-c C-p (org-previous-visible-heading)

Previous heading.

C-c C-f (org-forward-heading-same-level)

Next heading same level.

C-c C-b (org-backward-heading-same-level)

Previous heading same level.

C-c C-u (outline-up-heading)

Backward to higher level heading.

C-c C-j (org-goto)

Jump to a different place without changing the current outline visibility. Shows the document structure in a temporary buffer, where you can use the following keys to find your destination:

TAB Cycle visibility.
DOWN / UP Next/previous visible headline.
RET Select this location.
/ Do a Sparse-tree search

The following keys work if you turn off org-goto-auto-isearch.

n / p Next/previous visible headline.
f / b Next/previous headline same level.
u One level up.
09 Digit argument.
q Quit.

See also the variable org-goto-interface.

Structure Editing

M-RET (org-meta-return)

Insert a new heading, item, or row.

If the command is used at the beginning of a line, and if there is a heading or a plain list item (see Plain Lists) at point, the new heading/item is created before the current line. When used at the beginning of a regular line of text, turn that line into a heading.

When this command is used in the middle of a line, the line is split and the rest of the line becomes the new item or headline. If you do not want the line to be split, customize org-M-RET-may-split-line.

Calling the command with a C-u prefix unconditionally inserts a new heading at the end of the current subtree, thus preserving its contents. With a double C-u C-u prefix, the new heading is created at the end of the parent subtree instead.

C-RET (org-insert-heading-respect-content)

Insert a new heading at the end of the current subtree.

M-S-RET (org-insert-todo-heading)

Insert new TODO entry with same level as current heading. See also the variable org-treat-insert-todo-heading-as-state-change.

C-S-RET (org-insert-todo-heading-respect-content)

Insert new TODO entry with same level as current heading. Like C-RET, the new headline is inserted after the current subtree.

TAB (org-cycle)

In a new entry with no text yet, the first TAB demotes the entry to become a child of the previous one. The next TAB makes it a parent, and so on, all the way to top level. Yet another TAB, and you are back to the initial level.

M-LEFT (org-do-promote), M-RIGHT (org-do-demote)

Promote or demote current heading by one level.

When there is an active region—i.e., when Transient Mark mode is active—promotion and demotion work on all headlines in the region. To select a region of headlines, it is best to set mark at the beginning of the first headline, and point at the line just after the last headline to change.

M-S-LEFT (org-promote-subtree)

Promote the current subtree by one level.

M-S-RIGHT (org-demote-subtree)

Demote the current subtree by one level.

M-UP (org-move-subtree-up)

Move subtree up, i.e., swap with previous subtree of same level.

M-DOWN (org-move-subtree-down)

Move subtree down, i.e., swap with next subtree of same level.

C-c @ (org-mark-subtree)

Mark the subtree at point. Hitting it repeatedly marks subsequent subtrees of the same level as the marked subtree.

C-c C-x C-w (org-cut-subtree)

Kill subtree, i.e., remove it from the buffer but save in kill ring. With a numeric prefix argument N, kill N sequential subtrees.

C-c C-x M-w (org-copy-subtree)

Copy subtree to kill ring. With a numeric prefix argument N, copy the N sequential subtrees.

C-c C-x C-y (org-paste-subtree)

Yank subtree from kill ring. This does modify the level of the subtree to make sure the tree fits in nicely at the yank position. The yank level can also be specified with a numeric prefix argument, or by yanking after a headline marker like ****. With C-u prefix, force inserting as a sibling. With C-u C-u prefix argument, force inserting as a child.

C-y (org-yank)

Depending on the variables org-yank-adjusted-subtrees and org-yank-folded-subtrees, Org's internal yank command pastes subtrees folded and in a clever way, using the same command as C-c C-x C-y. With the default settings, no level adjustment takes place, but the yanked tree is folded unless doing so would swallow text previously visible. Any prefix argument to this command forces a normal yank to be executed, with the prefix passed along. A good way to force a normal yank is C-u C-y. If you use yank-pop after a yank, it yanks previous kill items plainly, without adjustment and folding.

C-c C-x c (org-clone-subtree-with-time-shift)

Clone a subtree by making a number of sibling copies of it. You are prompted for the number of copies to make, and you can also specify whether any timestamps in the entry should be shifted. This can be useful, for example, to create a number of tasks related to a series of lectures to prepare. For more details, see the docstring of the command org-clone-subtree-with-time-shift.

C-c C-w (org-refile)

Refile entry or region to a different location. See Refile and Copy.

C-c ^ (org-sort)

Sort same-level entries. When there is an active region, all entries in the region are sorted. Otherwise, the children of the current headline are sorted. The command prompts for the sorting method, which can be alphabetically, numerically, by time—first timestamp with active preferred, creation time, scheduled time, deadline time—by priority, by TODO keyword—in the sequence the keywords have been defined in the setup—or by the value of a property. Reverse sorting is possible as well. You can also supply your own function to extract the sorting key. With a C-u prefix, sorting is case-sensitive.

C-x n s (org-narrow-to-subtree)

Narrow buffer to current subtree.

C-x n b (org-narrow-to-block)

Narrow buffer to current block.

C-x n w (widen)

Widen buffer to remove narrowing.

C-c * (org-toggle-heading)

Turn a normal line or plain list item into a headline—so that it becomes a subheading at its location. Also turn a headline into a normal line by removing the stars. If there is an active region, turn all lines in the region into headlines. If the first line in the region was an item, turn only the item lines into headlines. Finally, if the first line is a headline, remove the stars from all headlines in the region.

Note that when point is inside a table (see Tables), the Meta-Cursor keys have different functionality.

Sparse Trees

An important feature of Org mode is the ability to construct sparse trees for selected information in an outline tree, so that the entire document is folded as much as possible, but the selected information is made visible along with the headline structure above it(note: See also the variable org-fold-show-context-detail to decide how much context is shown around each match.). Just try it out and you will see immediately how it works.

Org mode contains several commands creating such trees, all of which can be accessed through a dispatcher:

C-c / (org-sparse-tree)

This prompts for an extra key to select a sparse-tree creating command.

C-c / r or C-c / / (org-occur)

Prompts for a regexp (see Regular Expressions) and shows a sparse tree with all matches. If the match is in a headline, the headline is made visible. If the match is in the body of an entry, the headline and body are made visible. In order to provide minimal context, also the full hierarchy of headlines above the match is shown, as well as the headline following the match. Each match is also highlighted; the highlights disappear when the buffer is changed by an editing command, or by pressing =C-c C-c=(note: This depends on the option org-remove-highlights-with-change.). When called with a C-u prefix argument, previous highlights are kept, so several calls to this command can be stacked.

M-g n or M-g M-n (next-error)

Jump to the next sparse tree match in this buffer.

M-g p or M-g M-p (previous-error)

Jump to the previous sparse tree match in this buffer.

For frequently used sparse trees for specific search strings, you can use the variable org-agenda-custom-commands to define fast keyboard access to specific sparse trees. These commands will then be accessible through the agenda dispatcher (see The Agenda Dispatcher). For example:

(setq org-agenda-custom-commands
      '(("f" occur-tree "FIXME")))

defines the key f as a shortcut for creating a sparse tree matching the string FIXME.

The other sparse tree commands select headings based on TODO keywords, tags, or properties and are discussed later in this manual.

To print a sparse tree, you can use the Emacs command ps-print-buffer-with-faces, which does not print invisible parts of the document. Or you can use the command C-c C-e C-v to export only the visible part of the document and print the resulting file.

Plain Lists

Within an entry of the outline tree, hand-formatted lists can provide additional structure. They also provide a way to create lists of checkboxes (see Checkboxes). Org supports editing such lists, and every exporter (see Exporting) can parse and format them.

Org knows ordered lists, unordered lists, and description lists.

  • Unordered list items start with -, +, or * 3 as bullets.

Ordered list items start with a numeral followed by either a period or a right parenthesis(note: You can filter out any of them by configuring org-plain-list-ordered-item-terminator.), such as 1.

or 1) 4 If you want a list to start with a different

value—e.g., 20—start the text of the item with [@20] 5. Those constructs can be used in any item of the list in order to enforce a particular numbering.

  • Description list items are unordered list items, and contain the separator :: to distinguish the description term from the description text.

Items belonging to the same list must have the same indentation on the first line. In particular, if an ordered list reaches number 10., then the 2-digit numbers must be written left-aligned with the other numbers in the list. An item ends before the next line that has an indentation less than or equal to its bullet/number.

A list ends whenever every item has ended, which means before any line with an indentation less than or equal to that of the top-level items. It also ends before two blank lines. In that case, all items are closed. Here is an example:

* Lord of the Rings
My favorite scenes are (in this order)
1. The attack of the Rohirrim
2. Eowyn's fight with the witch king
   + this was already my favorite scene in the book
   + I really like Miranda Otto.
3. Peter Jackson being shot by Legolas
   - on DVD only
   He makes a really funny face when it happens.
8. [@8] <favorite scenes 4 to 8 are skipped for brevity>
But in the end, no individual scenes matter but the film as a whole.
Important actors in this film are:
- Elijah Wood :: He plays Frodo
- Sean Astin :: He plays Sam, Frodo's friend.  I still remember him
     very well from his role as Mikey Walsh in /The Goonies/.

Org supports these lists by tuning filling and wrapping commands to deal with them correctly, and by exporting them properly (see Exporting). Since indentation is what governs the structure of these lists, many structural constructs like #+BEGIN_ blocks can be indented to signal that they belong to a particular item.

If you find that using a different bullet for a sub-list—than that used for the current list-level—improves readability, customize the variable org-list-demote-modify-bullet. To get a greater difference of indentation between items and their sub-items, customize org-list-indent-offset.

The following commands act on items when point is in the first line of an item—the line with the bullet or number. Some of them imply the application of automatic rules to keep list structure intact. If some of these actions get in your way, configure org-list-automatic-rules to disable them individually.

TAB (org-cycle)

Items can be folded just like headline levels. Normally this works only if point is on a plain list item. For more details, see the variable org-cycle-include-plain-lists. If this variable is set to integrate, plain list items are treated like low-level headlines. The level of an item is then given by the indentation of the bullet/number. Items are always subordinate to real headlines, however; the hierarchies remain completely separated. In a new item with no text yet, the first TAB demotes the item to become a child of the previous one. Subsequent =TAB=s move the item to meaningful levels in the list and eventually get it back to its initial position.

M-RET (org-insert-item)

Insert new item at current level. With a prefix argument, force a new heading (see Structure Editing). If this command is used in the middle of an item, that item is split in two, and the second part becomes the new item(note: If you do not want the item to be split, customize the variable org-M-RET-may-split-line.). If this command is executed before the item's body, the new item is created before the current one.

M-S-RET

Insert a new item with a checkbox (see Checkboxes).

S-UP, S-DOWN

Jump to the previous/next item in the current list, but only if org-support-shift-select is off(note: If you want to cycle around items that way, you may customize org-list-use-circular-motion.). If not, you can still use paragraph jumping commands like C-UP and C-DOWN to quite similar effect.

M-UP, M-DOWN

Move the item including sub-items up/down(note: See org-list-use-circular-motion for a cyclic behavior.), i.e., swap with previous/next item of same indentation. If the list is ordered, renumbering is automatic.

M-LEFT, M-RIGHT

Decrease/increase the indentation of an item, leaving children alone.

M-S-LEFT, M-S-RIGHT

Decrease/increase the indentation of the item, including sub-items. Initially, the item tree is selected based on current indentation. When these commands are executed several times in direct succession, the initially selected region is used, even if the new indentation would imply a different hierarchy. To use the new hierarchy, break the command chain by moving point.

As a special case, using this command on the very first item of a list moves the whole list. This behavior can be disabled by configuring org-list-automatic-rules. The global indentation of a list has no influence on the text after the list.

C-c C-c

If there is a checkbox (see Checkboxes) in the item line, toggle the state of the checkbox. In any case, verify bullets and indentation consistency in the whole list.

C-c -

Cycle the entire list level through the different itemize/enumerate bullets (-, +, *, 1., 1)) or a subset of them, depending on org-plain-list-ordered-item-terminator, the type of list, and its indentation. With a numeric prefix argument N, select the Nth bullet from this list. If there is an active region when calling this, all lines are converted to list items. With a prefix argument, the selected text is changed into a single item. If the first line already was a list item, any item marker is removed from the list. Finally, even without an active region, a normal line is converted into a list item.

C-c *

Turn a plain list item into a headline—so that it becomes a subheading at its location. See Structure Editing for a detailed explanation.

C-c C-*

Turn the whole plain list into a subtree of the current heading. Checkboxes (see Checkboxes) become TODO or DONE keywords when unchecked or checked, respectively.

S-LEFT, S-RIGHT

This command also cycles bullet styles when point is on the bullet or anywhere in an item line, with details depending on org-support-shift-select.

C-c ^

Sort the plain list. Prompt for the sorting method: numerically, alphabetically, by time, or by custom function.

Drawers

Sometimes you want to keep information associated with an entry, but you do not normally want to see it. For this, Org mode has drawers. They can contain anything but a headline and another drawer. Drawers look like this:

** This is a headline
Still outside the drawer
:DRAWERNAME:
This is inside the drawer.
:END:
After the drawer.

You can interactively insert a drawer at point by calling org-insert-drawer, which is bound to C-c C-x d. With an active region, this command puts the region inside the drawer. With a prefix argument, this command calls non-interactive function org-insert-property-drawer, which creates a PROPERTIES drawer right below the current headline. Org mode uses this special drawer for storing properties (see Properties and Columns). You cannot use it for anything else.

Completion over drawer keywords is also possible using

M-TAB 6.

Visibility cycling (see Visibility Cycling) on the headline hides and shows the entry, but keeps the drawer collapsed to a single line. In order to look inside the drawer, you need to move point to the drawer line and press TAB there.

You can also arrange for state change notes (see Tracking TODO state changes) and clock times (see Clocking Work Time) to be stored in a LOGBOOK drawer. If you want to store a quick note there, similarly to state changes, use

C-c C-z

Add a time-stamped note to the LOGBOOK drawer.

Blocks

Org mode uses #+BEGIN#+END blocks for various purposes, from including source code examples (see Literal Examples) to capturing time logging information (see Clocking Work Time). These blocks can be folded and unfolded by pressing TAB in the #+BEGIN line. You can also get all blocks folded at startup by configuring the variable org-hide-block-startup or on a per-file basis by using

#+STARTUP: hideblocks
#+STARTUP: nohideblocks

Footnotes

  1. 1

    See the variables org-special-ctrl-a/e, org-special-ctrl-k, and org-ctrl-k-protect-subtree to configure special behavior of C-a, C-e, and C-k in headlines. Note also that clocking only works with headings indented less than 30 stars.

    Backrefs: 1

  2. 2

    The indirect buffer contains the entire buffer, but is narrowed to the current tree. Editing the indirect buffer also changes the original buffer, but without affecting visibility in that buffer. For more information about indirect buffers, see GNU Emacs Manual.

    Backrefs: 1

  3. 3

    When using * as a bullet, lines must be indented so that they are not interpreted as headlines. Also, when you are hiding leading stars to get a clean outline view, plain list items starting with a star may be hard to distinguish from true headlines. In short: even though * is supported, it may be better to not use it for plain list items.

    Backrefs: 1

  4. 4

    You can also get a., A., a) and A) by configuring org-list-allow-alphabetical. To minimize confusion with normal text, those are limited to one character only. Beyond that limit, bullets automatically become numbers.

    Backrefs: 1

  5. 5

    If there's a checkbox in the item, the cookie must be put before the checkbox. If you have activated alphabetical lists, you can also use counters like [@b].

    Backrefs: 1

  6. 6

    Many desktops intercept M-TAB to switch windows. Use C-M-i or ESC TAB instead.

    Backrefs: 1

Manual
Org Mode 9.8.5
Source Ref
release_9.8.5
Source
View upstream