“Unix is user-friendly -- it's just choosy about who its friends are.”
-- anonymous
在网上找了几篇中文的 Emacs 入门文档, 都不是太好, 最大的问题在于没有注明快捷键对应的英文缩写是什么,因为我的英文能力还没到看到一个字母就能完全猜出她对应的单词是什么。所以, 我选择了 Emacs 官网入门文档作为起点:
http://www.gnu.org/software/emacs/tour/
什么是 buffer
在读 Emacs 的文档的时候, 我们时常会遇到这个词 buffer. 那么什么是 buffer, 她于 file 的区别是什么呢?
“You don't really edit files with Emacs. Instead, Emacs copies the contents of a file into a temporary buffer and you edit that. The file on disk doesn't change until you save the buffer. Like files, Emacs buffers have names. The name of a buffer is usually the same as the name of the file that you're editing. There are a few exceptions. Some buffers don't have associated files—for example, *scratch* is just a temporary practice buffer, like a scratchpad; the help facility displays help messages in a buffer named *Help* , which also isn't connected to a file.”-- From 《Learning GNU Emacs》3rd Edition
快捷键
Emacs 中定义了大量的快捷键,各种插件也经常会定义自己的快捷键。在Emacs的文档中,通常会使用一种简短的方式来介绍快捷键:
- 大写 C 表示 Control 键
- 大写 M 表示 Alt 键 -- 它的出处在于有些机器的键盘上会有称为Meta的功能键。
- 同时按下若干键时,用 - 号表示分隔,如 C-f 表示同时按下 Control 和 f 键。
- 按键有先后时,用空格分隔,如C-x f,表示同时按下 Control 和 x,然后松开,再按下 f。
取消目前的指令和操作:
C-g
例如: 如果我按了 C-x C-f 就会被要求输入要打开的文件全路径, 但是我又不想打开了, 就可以按下 C-g。返回编辑模式。
也可以用来中止一条执行过久的指令。
退出 Emacs:
C-x C-c
取消上一步操作:
C-x u
打开 Emacs 自带的入门教程:
C-h t
进入 File manager mode:
命令:
M-x (即 Alt + x)
基本的光标移动:
C-f -> Forward one character 左移一位
C-b -> Back one character 右移一位
C-n -> Next line 下一行
C-p -> Previous line 上一行
magic 光标启动:(我起的名字)
C-a -> Beginning of line
C-e -> End of line
向右移动一个词【对中文是移动到下一个标点符号 M-f
向左移动一个词【对中文是移动到上一个标点符号 M-b
前一屏 M-v
后一屏 C-v
移动到行首 C-a
移动到行尾 C-e
助记:
META 系列组合键用来操作“由语言定义的单位(比如词、句子、段落)”,而 CONTROL系列组合键用来操作“与语言无关的基本单位(比如字符、行等等)”。
移动到文档开头 M-< (注意这里要按住 SHIFT 键来使用 <)
移动到文档结尾 M->
向前移动 8 个字 C-u 8 C-f
多窗口:
把当前窗口上下等分为两份 C-x 2
把当前窗口左右等分为两份 C-x 3
窗口间的切换 C-x o (other-window)
关闭当前窗口 C-x 0
关闭当前窗口外的其他所有窗口 C-x 1
Python相关:
切换到 Python 编辑模式 M-x python-mode
插入新的一行,缩进与上一行相同 C-j
python-mode插件:
https://launchpad.net/python-mode
编辑:
删除当前字符 C-d
删除前一个字符 Backspace