org-mode进阶
之前写过一个初试org-mode,里面介绍了一些基本的org-mode功能。
最近研究了一下org-mode,发现里面还是有很多实用的功能。
之前一直用spacemacs,后来是spacemacs-base,现在换成原生Emacs了,自己配置初始化文件。
初始化文件
;; -*- coding: utf-8 -*-
(require 'org-habit)
(require 'org-superstar)
(setq package-archives '(("gnu" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
("melpa" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/stable-melpa/")))
(package-initialize) ;; You might already have this line
(prefer-coding-system 'utf-8)
(load-theme 'gotham t)
(tool-bar-mode 0)
(menu-bar-mode 0)
(scroll-bar-mode 0)
(tooltip-mode 0)
(display-battery-mode 1)
(column-number-mode 1)
(electric-pair-mode 1)
(desktop-save-mode 1)
(setq ring-bell-function 'ignore)
(setq make-backup-files nil)
;; (add-to-list 'default-frame-alist '(fullscreen . maximized))
(toggle-frame-maximized)
(add-hook 'org-mode-hook (lambda () (org-superstar-mode 1)))
(setq inhibit-startup-message t)
(global-hl-line-mode 1)
(load-file "~/.emacs.d/agenda.el")
(org-agenda-list)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(package-selected-packages '(dracula-theme htmlize org-superstar gotham-theme)))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:family "等距更纱黑体 SC" :foundry "outline" :slant normal :weight normal :height 110 :width normal)))))Emacs基本操作
推荐开启menu-bar-mode了解对应按键。
| 键 | 命令 |
|---|---|
| C-x 0 | 关闭buffer |
| C-x k | 杀死buffer(让buffer完全消失) |
| C-x b | 切换buffer |
| C-x h | 全选 |
| C-x u | 撤销 |
| C-y | 粘贴 |
| M-w | 复制 |
| M-x | 运行命令 |
主题
~~目前推荐使用Gotham,富有科技感的主题。~~已经换到doom-themes了,现在在用doom-material-dark主题,基于gruvbox改的。
org-capture
一开始并没有深入使用org-capture,在深入了解之后发现这个记录功能非常强大。
(setq org-capture-templates
'(("t" "Task" entry (file+headline org-default-notes-file "Tasks")
"* TODO %?\n %i\n")
("s" "Study" entry (file+headline org-default-notes-file "Study")
"* TODO %? %^G\n%u %i\n")
("o" "Other" entry (file+headline org-default-notes-file "Others")
"* TODO %?\n%u %i\n")
("r" "Record")
("rr" "Record" entry (file+datetree "record.org")
"* %? :record:\n%T\n")
("rc" "Record Clock" entry (file+datetree "record.org")
"* %? :record:\n%T" :clock-in t :clock-keep t)
("e" "Event" entry (file+datetree "record.org")
"* %? :event:\n%^T\n")
("j" "Journal" plain (file+datetree "journal.org")
"%U\n%?" :unnarrowed t)
("o" "Others")
("ot" "Ted" entry (file+olp org-default-notes-file "Others" "Ted")
"* TODO %?\n%u")
("op" "Podcast" entry (file+olp org-default-notes-file "Others" "Podcast")
"* TODO %?\n%u")
("ob" "Book" entry (file+headline org-default-notes-file "Book")
"* TODO %?\n%u")
))org-capture自带一个datetree功能,可以在org文件里生成一个通过日期分类的大纲,只要把前面设为file+datetree即可。
我把datetree专门放在了一个record.org文件里。里面都记录了一个时间戳,可以在org-agenda里显示记录的内容。普通的记录用%T可以自动添加时间戳。对于事件,用%^T,可以弹出一个时间选择器。而用%^G(或%^g)可以弹出一个标签选择器(支持TAB补全)。
一些特殊标识符:
| 表示 | 描述 |
|---|---|
%t | 现在日期 |
%u | 现在日期(非活动) |
%T(或%U) | 现在日期和时间 |
%? | 光标停留位置 |
%x | 剪贴板内容 |
分组
如果给每个项目都只定一个键那么就会很混乱,所以org-capture自带了一个分组的功能,比如要按两下r键记录,按rc记录另一个,可以在前面添加一个("r" "Record")进行分组。
("r" "Record")
("rr" "Record" entry (file+datetree "record.org")
"* %? :record:\n%T\n")
("rc" "Record Clock" entry (file+datetree "record.org")
"* %? :record:\n%T" :clock-in t :clock-keep t)快捷org-agenda命令
之前一直使用复杂的C-c C-t这种复杂的命令,其实在org-agenda里有很多一键触发的快捷指令。
| 键 | Evil键 | 命令 |
|---|---|---|
| b | [[ | 向前 |
| f | ]] | 向后 |
| d | gDd | 日视图 |
| e | ce | 设定 |
| w | gDw | 周视图 |
| t | 切换TODO | |
| l | gDl | Log mode |
| r | 刷新 | |
| R | cr | Clocktable mode |
| : | ct | 设置标签 |
| . | 跳转至今天 | |
| o | 最大化(同C-x 1) | |
| I | 开始计时 | |
| O | 停止计时 | |
| X | cc | 取消计时 |
| J | cg | 跳转至正在计时的任务 |
| S | C-x C-s | 保存所有org文件 |
| / | st | 筛选(按标签或CATEGOTY) |
| | | S | 去除筛选 |
| a | da | 归档 |
| c | ac | 跳转至日历 |
| z | a | 添加笔记 |
| m | < | 标记 |
| B | x | 对标记的部分批量操作 |
按v(Evil:gD)键可以切换查看模式。
| 键 | 命令 |
|---|---|
| v t | 两周视图 |
| v m | 月视图 |
| v y | 年视图 |
| v a | 包括已归档 |
| v c | Clockcheck视图 |
| v E | 查看条目内部文字 |
| v [ | 包括非活动时间戳 |
分屏
Emacs原生支持分屏,可以让很多窗口显示在一起。
| 键 | 命令 |
|---|---|
| C-x 0 | 关闭窗口 |
| C-x 1 | 最大化(关闭其他窗口) |
| C-x 2 | 在下面分屏 |
| C-x 3 | 在左侧分屏 |
org-attach
org-attach可以给org文件里的标题添加附件,默认按C-c C-a就可以激活。
激活之后按a输入一个路径,这个标题就会添加上一个ID属性,文件会移动到org目录的data文件夹里,打开按C-c C-a o就行了。
C-c C-a s命令可以给标题设置一个路径
标签
Org-mode可以给标签设置快捷键,这样不用在设置标签时按TAB补全,只要在设置org-tag-alist里把标签改成("tag" . ?t),这样在输入时就可以直接按t来设置标签了。
注意如果使用(:startgroup)和(:endgroup)中的标签是只能在其中选择一个,标签选择界面显示为花括号。如果要临时选择多个标签,按!临时关闭分组。
(setq org-tag-persistent-alist '((:startgroup)
("eng")
("math")
("chs")
("phy")
("che")
("his")
(:endgroup)
("games")
("药" . ?y)
("podcast")
("video")
("book")
("sports")
("record")
("event")
("emacs")
("tiddlywiki")
(:startgroup)
("video")
(:grouptags)
("ted")
("bilibili")
("movie")
(:endgroup)))设置标签的命令:
| 键 | 命令 |
|---|---|
| ! | 关闭分组 |
| TAB | 用原标签输入添加标签 |
| SPC | 清除所有标签 |
最后是一个标签缩进的问题,默认标签距离标题很远。如果想要标签距离标题一个空格,可以添加:
(setq org-tags-column 0)org内置实用模块
org-mouse
让org-mode有鼠标支持,比如可以点击打开或折叠标题。
org-habit
可以显示重复任务为热力图。
org-contrib
org-contrib是一个org-mode第三方插件集合,里面有很多实用插件
org-expiry
org-expiry可以用EXPIRY属性自动添加:ARCHIVE:标签,首先用M-x执行org-expiry-insert-expiry添加一个属性。到后面执行org-expiry-process-entries就可以了。
org-sudoku
可以在org-mode里自动生成数独表格!
Sudoku
| 3 | 4 | 2 | ||||||
|---|---|---|---|---|---|---|---|---|
| 2 | 7 | 1 | 6 | 9 | ||||
| 9 | 3 | 2 | ||||||
| 8 | 6 | 5 | ||||||
| 4 | 6 | |||||||
| 1 | 6 | 9 | ||||||
| 5 | 1 | 8 | 6 | 2 | 9 | 3 | ||
| 7 | 3 | 4 | 1 | |||||
| 4 | 3 | 7 | 8 | 6 | 2 |
自定义归档
;; Archive
(setq org-archive-location "D:/Notes/org-mode/archive.org::* From %s")参考
Footnotes
四年前的11月,此人就已经放弃了折腾工具。(2026.5.21) ↩