11.3.3 Matching tags and properties
If headlines in the agenda files are marked with tags (see Tags), or have properties (see Properties and Columns), you can select headlines based on this metadata and collect them into an agenda buffer. The match syntax described here also applies when creating sparse trees with C-c / m
.
M-x org-agenda m
(org-tags-view
)β
Produce a list of all headlines that match a given set of tags. The command prompts for a selection criterion, which is a boolean logic expression with tags, like β+work+urgent-withboss
β or βwork|home
β (see Tags). If you often need a specific search, define a custom command for it (see Agenda Dispatcher).
M-x org-agenda M
(org-tags-view
)β
Like m
, but only select headlines that are also TODO items and force checking subitems (see the variable org-tags-match-list-sublevels
). To exclude scheduled/deadline items, see the variable org-agenda-tags-todo-honor-ignore-options
. Matching specific TODO keywords together with a tags match is also possible, see Tag Searches.
The commands available in the tags list are described in Agenda Commands.
A search string can use Boolean operators β&
β for AND and β|
β for OR. β&
β binds more strongly than β|
β. Parentheses are currently not implemented. Each element in the search is either a tag, a regular expression matching tags, or an expression like βPROPERTY OPERATOR VALUE
β with a comparison operator, accessing a property value. Each element may be preceded by β-
β to select against it, and β+
β is syntactic sugar for positive selection. The AND operator β&
β is optional when β+
β or β-
β is present. Here are some examples, using only tags.
β+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
β.
Instead of a tag, you may also specify a regular expression enclosed in curly braces. For example, βwork+{^boss.*}
β matches headlines that contain the tag β:work:
β and any tag starting with βboss
β.
Group tags (see Tag Hierarchy) are expanded as regular expressions. E.g., if βwork
β is a group tag for the group β:work:lab:conf:
β, then searching for βwork
β also searches for β{\(?:work\|lab\|conf\)}
β and searching for β-work
β searches for all headlines but those with one of the tags in the group (i.e., β-{\(?:work\|lab\|conf\)}
β).
You may also test for properties (see Properties and Columns) at the same time as matching tags. The properties may be real properties, or special properties that represent other metadata (see Special Properties). For example, the property βTODO
β represents the TODO keyword of the entry. Or, the property βLEVEL
β represents the level of an entry. So searching β+LEVEL=3+boss-TODOβ="DONE"
β lists all level three headlines that have the tag βboss
β and are not marked with the TODO keyword βDONE
β. In buffers with org-odd-levels-only
set, βLEVEL
β does not count the number of stars, but βLEVEL=2
β corresponds to 3 stars etc.
Here are more examples:
βwork+TODOβ="WAITING"
ββ
Select βwork
β-tagged TODO lines with the specific TODO keyword βWAITING
β.
βwork+TODOβ="WAITING"|home+TODOβ="WAITING"
ββ
Waiting tasks both at work and at home.
When matching properties, a number of different operators can be used to test the value of a property. Here is a complex example:
+work-boss+PRIORITY="A"+Coffee="unlimited"+Effort<2
+With={Sarah|Denny}+SCHEDULED>="<2008-10-11>"
The type of comparison depends on how the comparison value is written:
- If the comparison value is a plain number, a numerical comparison is done, and the allowed operators are β
<
β, β=
β, β>
β, β<=
β, β>=
β, and β<>
β. - If the comparison value is enclosed in double-quotes, a string comparison is done, and the same operators are allowed.
- If the comparison value is enclosed in double-quotes and angular brackets (like β
DEADLINE<β="<2008-12-24 18:30>"
β), both values are assumed to be date/time specifications in the standard Org way, and the comparison is done accordingly. Valid values also include β"<now>"
β for now (including time), β"<today>"
β, and β"<tomorrow>"
β for these days at 0:00 hours, i.e., without a time specification. You can also use strings like β"<+5d>"
β or β"<-2m>"
β with units βd
β, βw
β, βm
β, and βy
β for day, week, month, and year, respectively. - If the comparison value is enclosed in curly braces, a regexp match is performed, with β
=
β meaning that the regexp matches the property value, and β<>
β meaning that it does not match.
So the search string in the example finds entries tagged βwork
β but not βboss
β, which also have a priority value βA
β, a βCoffee
β property with the value βunlimited
β, an βEFFORT
β property that is numerically smaller than 2, a βWith
β property that is matched by the regular expression βSarah|Denny
β, and that are scheduled on or after October 11, 2008.
You can configure Org mode to use property inheritance during a search, but beware that this can slow down searches considerably. See Property Inheritance, for details.
For backward compatibility, and also for typing speed, there is also a different way to test TODO states in a search. For this, terminate the tags/property part of the search string (which may include several terms connected with β|
β) with a β/
β and then specify a Boolean expression just for TODO keywords. The syntax is then similar to that for tags, but should be applied with care: for example, a positive selection on several TODO keywords cannot 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 (resulting in a speed-up), use M-x org-agenda M
, or equivalently start the TODO part after the slash with β!
β. Using M-x org-agenda M
or β/!
β does not match TODO keywords in a DONE state. Examples:
βwork/WAITING
ββ
Same as βwork+TODOβ="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
β.