使用org-habit管理习惯
2026年8月26日 2026年8月30日
说明
org-habit作为org提供的模块之一,可以在时间轴上显示习惯的保持情况。
如:遛弯。
TODO标题如下
* TODO 遛弯
SCHEDULED: <2026-08-25 周二 .+2d/4d>
:PROPERTIES:
:STYLE: habit
:LAST_REPEAT: [2026-08-23 周日 06:18]
:END:
:LOGBOOK:
- State "DONE" from "TODO" [2026-08-23 周日 06:18]
- State "DONE" from "TODO" [2026-08-22 周六 05:49]
- State "DONE" from "TODO" [2026-08-20 周四 03:55]
- State "DONE" from "TODO" [2026-08-18 周二 03:55]
- State "DONE" from "TODO" [2026-08-13 周四 03:55]
- State "DONE" from "TODO" [2026-08-12 周三 03:55]
- State "TODO" from [2026-08-11 周二 01:33]
:END:
输出如下
使能org-habit
[orgmode]5.3.3 Tracking your habits
使用内置org。
elisp
1(use-package org
2 :config
3 (add-to-list 'org-modules 'org-habit)
4 (require 'org-habit)
5 )
验证
elisp
1(featurep 'org-habit)
org-habit配置
将记录写在LOGBOOK区域
elisp
1(setq org-log-into-drawer t)
记录插入TODO标题时间
- [C-c C-t t]使标题状态变为TODO;进入TODO状态自动记录时间戳
- [C-c C-t d]使标题状态变为DONE;进入DONE状态自动记录时间戳;对习惯更新[LAST_REPEAT]
elisp
1(setq org-todo-keywords '((sequence "TODO(t!)" "|" "DONE(d!)")))
2(setq org-treat-insert-todo-heading-as-state-change t)
设置图表宽度
elisp
1(setq org-habit-graph-column 40)
图表涵盖天数范围
elisp
1;; 从左到右
2(setq org-habit-preceding-days 20) ;; 今天之前,过去天数
3(setq org-habit-following-days 20) ;; 今天在内,未来天数
今天完成习惯后,是否显示
t 为显示。
注意:TODO标题永远为TODO状态。
elisp
1(setq org-habit-show-all-today t)
是否在未开始日期显示习惯
t 为不显示。
elisp
1(setq org-habit-show-habits-only-for-today t)
色块文本
含义
!
- 今天
- 任务还未完成
*
- 当天已完成任务
- 过去/今天
支持自定义
elisp
1(setq org-habit-today-glyph ?◆)
2(setq org-habit-completed-glyph ?◉)
进阶:修改函数org-habit-build-graph
其余情况设置字符。
elisp
1(cond
2 (donep
3 (aset graph index org-habit-completed-glyph)
4 (setq markedp t)
5 (while (and done-dates (= start (car done-dates)))
6 (setq last-done-date (car done-dates))
7 (setq done-dates (cdr done-dates))))
8 (todayp
9 (aset graph index org-habit-today-glyph))
10 (t
11 (aset graph index ?○))
12 )
效果如下
org-habit图表样式
4组共8个样式。
其中,foreground为字体颜色,background为色块颜色。
| Face | Documentation |
|---|---|
| org-habit-clear-face | Face for days on which a task shouldn’t be done yet. |
| org-habit-clear-future-face | Face for future days on which a task shouldn’t be done yet. |
| org-habit-ready-face | Face for days on which a task should start to be done. |
| org-habit-ready-future-face | Face for days on which a task should start to be done. |
| org-habit-alert-face | Face for days on which a task is due. |
| org-habit-alert-future-face | Face for days on which a task is due. |
| org-habit-overdue-face | Face for days on which a task is overdue. |
| org-habit-overdue-future-face | Face for days on which a task is overdue. |
注释仅供参考。
习惯正常保持区
.+md
严格满足(m)天内必有一次习惯完成。
elisp
1;; 当天不必完成习惯;可以显示文本!/*
2(set-face-attribute 'org-habit-clear-face nil
3 :background "blue" :foreground "white")
4
5;; 其余不必完成习惯的日子
6(set-face-attribute 'org-habit-clear-future-face nil
7 :background "purple")
合理提醒区
/nd
严格满足(n)天内必有一次习惯完成。
(n-m)天期间,负责提醒,需要完成一次任务。
elisp
1;; 当天需要完成任务,可显示文本!或*
2(set-face-attribute 'org-habit-ready-face nil
3 :background "grey" :foreground "white")
4
5;; 其余需要完成任务的日子
6(set-face-attribute 'org-habit-ready-future-face nil
7 :background "#89CFF0")
告警示意区
elisp
1;; 截止日期,当天仍可完成习惯,显示文本!
2(set-face-attribute 'org-habit-alert-face nil
3 :background "black" :foreground "white")
4
5;; 截止日期;过去确定逾期,未来可能逾期
6(set-face-attribute 'org-habit-alert-future-face nil
7 :background "orange")
逾期区
elisp
1;; 当天已逾期;若完成习惯,显示文本*
2(set-face-attribute 'org-habit-overdue-face nil
3 :background "red" :foreground "white")
4
5;; 逾期日期之后
6(set-face-attribute 'org-habit-overdue-future-face nil
7 :background "white")
TODO标题
必须包含以下内容
-
SCHEDULED
C-c C-sSCHEDULED: <2026-08-25 周二 .+1d/2d>.+nd表示每n天一次
/md表示m天内至少有一次 -
属性
:PROPERTIES: :STYLE: habit :END:
记录习惯的org文件路径需添加到[org-agenda-files]。