Previous: Setting tags, Up: Tags


6.3 Tag searches

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

C-c \
C-c / T
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.
C-c a m
Create a global list of tag matches from all agenda files. See Matching tags and properties.
C-c a M
Create a global list of tag matches from all agenda files, but check only TODO items and force checking subitems (see variable org-tags-match-list-sublevels).

A tags search string can use Boolean operators `&' for AND and `|' for OR. `&' binds more strongly than `|'. Parenthesis are currently not implemented. A tag may also be preceded by `-', to select against it, and `+' is syntactic sugar for positive selection. The AND operator `&' is optional when `+' or `-' is present. Examples:

`+work-boss'
Select headlines tagged `:work:', but discard those also tagged `:boss:'.
`work|laptop'
Selects lines tagged `:work:' or `:laptop:'.
`work|laptop&night'
Like before, but require the `:laptop:' lines to be tagged also `:night:'.

If you are using multi-state TODO keywords (see TODO extensions), it can be useful to also match on the TODO keyword. This can be done by adding a condition after a slash to a tags match. The syntax is similar to the tag matches, but should be applied with consideration: For example, a positive selection on several TODO keywords can not meaningfully be combined with boolean AND. However, negative selection combined with AND can be meaningful. To make sure that only lines are checked that actually have any TODO keyword, use C-c a M, or equivalently start the TODO part after the slash with `!'. Examples:

`work/WAITING'
Select `:work:'-tagged TODO lines with the specific TODO keyword `WAITING'.
`work/!-WAITING-NEXT'
Select `:work:'-tagged TODO lines that are neither `WAITING' nor `NEXT'
`work/+WAITING|+NEXT'
Select `:work:'-tagged TODO lines that are either `WAITING' or `NEXT'.

Any element of the tag/todo match can be a regular expression - in this case it must be enclosed in curly braces. For example, `work+{^boss.*}' matches headlines that contain the tag `:work:' and any tag starting with `boss'.

You can also require a headline to be of a certain level or category, by writing instead of any TAG an expression like `LEVEL=3' or `CATEGORY="work"', respectively. For example, a search `+LEVEL=3+boss/-DONE' lists all level three headlines that have the tag `boss' and are not marked with the TODO keyword DONE.