GNU Emacs
Org
Tags
Org 9.8.5 org

Tags

An excellent way to implement labels and contexts for cross-correlating information is to assign tags to headlines. Org mode has extensive support for tags.

Every headline can contain a list of tags; they occur at the end of the headline. Tags are normal words containing letters, numbers, _, @, #, and %. Tags must be preceded and followed by a single colon, e.g., :work:. Several tags can be specified, as in :work:urgent:. Tags by default are in bold face with the same color as the headline. You may specify special faces for specific tags using the variable org-tag-faces, in much the same way as you can for TODO keywords (see Faces for TODO keywords).

Tag Inheritance

Tags make use of the hierarchical structure of outline trees. If a heading has a certain tag, all subheadings inherit the tag as well. For example, in the list

* Meeting with the French group      :work:
** Summary by Frank                  :boss:notes:
*** TODO Prepare slides for him      :action:

the final heading has the tags work, boss, notes, and action even though the final heading is not explicitly marked with those tags. You can also set tags that all entries in a file should inherit just as if these tags were defined in a hypothetical level zero that surrounds the entire file. Use a line like this(note: As with all these in-buffer settings, pressing C-c C-c activates any changes in the line.)

#+FILETAGS: :Peter:Boss:Secret:

To limit tag inheritance to specific tags, or to turn it off entirely, use the variables org-use-tag-inheritance and org-tags-exclude-from-inheritance.

Tag inheritance is relevant when the agenda search tries to match a tag, either in the tags or tags-todo agenda types. In other agenda types, org-use-tag-inheritance has no effect. Still, you may want to have your tags correctly set in the agenda, so that tag filtering works fine, with inherited tags. Set org-agenda-use-tag-inheritance to control this: the default value includes all agenda types, but setting this to nil can really speed up agenda generation.

Setting Tags

Tags can simply be typed into the buffer at the end of a headline. After a colon, M-TAB offers completion on tags. There is also a special command for inserting tags:

C-c C-q (org-set-tags-command)

Enter new tags for the current headline. Org mode either offers completion or a special single-key interface for setting tags, see below. After pressing RET, the tags are inserted and aligned to org-tags-column. When called with a C-u prefix, all tags in the current buffer are aligned to that column, just to make things look nice. Tags are automatically realigned after promotion, demotion, and TODO state changes (see Basic TODO Functionality).

C-c C-c (org-set-tags-command)

When point is in a headline, this does the same as C-c C-q.

Org supports tag insertion based on a list of tags. By default, this list is constructed dynamically, containing all tags currently used in the buffer(note: To extend this default list to all tags used in all agenda files (see Agenda Views), customize the variable org-complete-tags-always-offer-all-agenda-tags.). You may also globally specify a hard list of tags with the variable org-tag-alist. Finally, you can set the default tags for a given file using the TAGS keyword, like

#+TAGS: @work @home @tennisclub
#+TAGS: laptop car pc sailboat

If you have globally defined your preferred set of tags using the variable org-tag-alist, but would like to use a dynamic tag list in a specific file, add an empty TAGS keyword to that file:

#+TAGS:

If you have a preferred set of tags that you would like to use in every file, in addition to those defined on a per-file basis by TAGS keyword, then you may specify a list of tags with the variable org-tag-persistent-alist. You may turn this off on a per-file basis by adding a STARTUP keyword to that file:

#+STARTUP: noptag

By default, Org mode uses the standard minibuffer completion facilities for entering tags. However, it also implements another, quicker, tag selection method called fast tag selection. This allows you to select and deselect tags with just a single key press. For this to work well you should assign unique letters to most of your commonly used tags. You can do this globally by configuring the variable org-tag-alist in your Emacs init file. For example, you may find the need to tag many items in different files with @home. In this case you can set something like:

(setq org-tag-alist '(("@work" . ?w) ("@home" . ?h) ("laptop" . ?l)))

If the tag is only relevant to the file you are working on, then you can instead set the TAGS keyword as:

#+TAGS: @work(w)  @home(h)  @tennisclub(t)  laptop(l)  pc(p)

The tags interface shows the available tags in a splash window. If you want to start a new line after a specific tag, insert \n into the tag list

#+TAGS: @work(w) @home(h) @tennisclub(t) \n laptop(l) pc(p)

or write them in two lines:

#+TAGS: @work(w)  @home(h)  @tennisclub(t)
#+TAGS: laptop(l)  pc(p)

You can also group together tags that are mutually exclusive by using braces, as in:

#+TAGS: { @work(w)  @home(h)  @tennisclub(t) }  laptop(l)  pc(p)

you indicate that at most one of @work, @home, and @tennisclub should be selected. Multiple such groups are allowed.

Do not forget to press C-c C-c with point in one of these lines to activate any changes.

To set these mutually exclusive groups in the variable org-tags-alist, you must use the dummy tags :startgroup and :endgroup instead of the braces. Similarly, you can use :newline to indicate a line break. The previous example would be set globally by the following configuration:

(setq org-tag-alist '((:startgroup . nil)
                      ("@work" . ?w) ("@home" . ?h)
                      ("@tennisclub" . ?t)
                      (:endgroup . nil)
                      ("laptop" . ?l) ("pc" . ?p)))

If at least one tag has a selection key then pressing C-c C-c automatically presents you with a special interface, listing inherited tags, the tags of the current headline, and a list of all valid tags with corresponding keys(note: Keys are automatically assigned to tags that have no configured keys.).

Pressing keys assigned to tags adds or removes them from the list of tags in the current line. Selecting a tag in a group of mutually exclusive tags turns off any other tag from that group.

In this interface, you can also use the following special keys:

TAB

Enter a tag in the minibuffer, even if the tag is not in the predefined list. You can complete on all tags present in the buffer and globally pre-defined tags from org-tag-alist and org-tag-persistent-alist. You can also add several tags: just separate them with a comma.

SPC

Clear all tags for this line.

RET

Accept the modified set.

C-g

Abort without installing changes.

q

If q is not assigned to a tag, it aborts like C-g.

!

Turn off groups of mutually exclusive tags. Use this to (as an exception) assign several tags from such a group.

C-c

Toggle auto-exit after the next change (see below). If you are using expert mode, the first C-c displays the selection window.

This method lets you assign tags to a headline with very few keys. With the above setup, you could clear the current tags and set @home, laptop and pc tags with just the following keys: C-c C-c SPC h l p RET. Switching from @home to @work would be done with C-c C-c w RET or alternatively with C-c C-c C-c w. Adding the non-predefined tag sarah could be done with C-c C-c TAB s a r a h RET.

If you find that most of the time you need only a single key press to modify your list of tags, set the variable org-fast-tag-selection-single-key. Then you no longer have to press RET to exit fast tag selection—it exits after the first change. If you then occasionally need more keys, press C-c to turn off auto-exit for the current tag selection process (in effect: start selection with C-c C-c C-c instead of C-c C-c). If you set the variable to the value expert, the special window is not even shown for single-key tag selection, it comes up only when you press an extra C-c.

The number of tags displayed in the fast tag selection interface is limited by org-fast-tag-selection-maximum-tags to avoid running out of keyboard keys. You can customize this variable.

Tag Hierarchy

Tags can be defined in hierarchies. A tag can be defined as a group tag for a set of other tags. The group tag can be seen as the "broader term" for its set of tags. Defining multiple group tags and nesting them creates a tag hierarchy.

One use-case is to create a taxonomy of terms (tags) that can be used to classify nodes in a document or set of documents.

When you search for a group tag, it returns matches for all members in the group and its subgroups. In an agenda view, filtering by a group tag displays or hides headlines tagged with at least one of the members of the group or any of its subgroups. This makes tag searches and filters even more flexible.

You can set group tags by using brackets and inserting a colon between the group tag and its related tags—beware that all whitespaces are mandatory so that Org can parse this line correctly:

#+TAGS: [ GTD : Control Persp ]

In this example, GTD is the group tag, and it is related to two other tags: Control, Persp. Defining Control and Persp as group tags creates a hierarchy of tags:

#+TAGS: [ Control : Context Task ]
#+TAGS: [ Persp : Vision Goal AOF Project ]

That can conceptually be seen as a hierarchy of tags:

  • GTD

    • Persp

      • Vision
      • Goal
      • AOF
      • Project
    • Control

      • Context
      • Task

You can use the :startgrouptag, :grouptags and :endgrouptag keyword directly when setting org-tag-alist directly:

(setq org-tag-alist '((:startgrouptag)
                      ("GTD")
                      (:grouptags)
                      ("Control")
                      ("Persp")
                      (:endgrouptag)
                      (:startgrouptag)
                      ("Control")
                      (:grouptags)
                      ("Context")
                      ("Task")
                      (:endgrouptag)))

The tags in a group can be mutually exclusive if using the same group syntax as is used for grouping mutually exclusive tags together; using curly brackets.

#+TAGS: { Context : @Home @Work @Call }

When setting org-tag-alist you can use :startgroup and :endgroup instead of :startgrouptag and :endgrouptag to make the tags mutually exclusive.

Furthermore, the members of a group tag can also be regular expressions, creating the possibility of a more dynamic and rule-based tag structure (see Regular Expressions). The regular expressions in the group must be specified within curly brackets. Here is an expanded example:

#+TAGS: [ Vision : {V@.+} ]
#+TAGS: [ Goal : {G@.+} ]
#+TAGS: [ AOF : {AOF@.+} ]
#+TAGS: [ Project : {P@.+} ]

Searching for the tag Project now lists all tags also including regular expression matches for P@.+, and similarly for tag searches on Vision, Goal and AOF. For example, this would work well for a project tagged with a common project-identifier, e.g., P@2014_OrgTags.

If you want to ignore group tags temporarily, toggle group tags support with org-toggle-tags-groups, bound to C-c C-x q. If you want to disable tag groups completely, set org-group-tags to nil.

Tag Searches

Once a system of tags has been set up, it can be used to collect related information into special lists.

C-c / m or C-c \ (org-match-sparse-tree)

Create a sparse tree with all headlines matching a tags search. With a C-u prefix argument, ignore headlines that are not a TODO line.

M-x org-agenda m (org-tags-view)

Create a global list of tag matches from all agenda files. See Matching tags and properties.

M-x org-agenda M (org-tags-view)

Create a global list of tag matches from all agenda files, but check only TODO items.

These commands all prompt for a match string which allows basic Boolean logic, such as +boss+urgent-project1 to find entries with tags boss and urgent, but not project1 or Kathy|Sally to find entries tagged with either Kathy or Sally. The full syntax of the search string is rich and allows also matching against TODO keywords, entry levels and properties. For a complete description with many examples, see Matching tags and properties.

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