子龙山人Learn Emacs in 21 Days: day 1 学习笔记
Youtube
youku
1. Install emacs
mac版本的emacs最近为25.1,2016年9月release。
https://emacsformacosx.com/builds
方装过程在此不再赘述,安装完后在应用程序中打开emacs.app即可运行eamcs。
2. Tutorials
首次打开emacs,点击Emacs Tutorials可以查看emacs内建的使用教程,也可以通过C-h t打开tutorials。
C-h t 中 C-h 为pre-key,意思为按住Control的同时按下h键,松开后emacs会等待输入,此时则可输入h。
M-x 中 M-为Meta键,Mac下为Option键,windows下为Alt键,M-x则为按住Option键的同时按下x键。
以下为一些常用操作的记录。
C-x C-f 打开文件。
C-x C-s 保存文件。
C-g 取消命令。如打算输入命令C-h t,输入C-h后不想继续命令,输入C-g即可终止此命令。
C-v 向下翻页
M-v 向上翻页
C-l 将光标置于emacs的中央
C-f 光标往前一个字符移动(forward)
C-b 光标往后一个字符移动(backward)
C-p 光标往前一行移动(previous)
C-n 光标往后一行移动(next)
M-f 光标往前一个单词移动(forward)
M-b 光标往后一个单词移动(backward)
C-a 光标移动到行首
C-e 光标移动到行末
M-a 光标移动到句首
M-e 光标移动到句末
C-u 8 C-n 光标往后8行移动,其它命令似类
C-h k 查看某个命令的描述
C-h f 查看某个函数的描述
C-h k 和 C-h f 打开的buffer可以通过光标选中后按q键关闭。
C-h c 查看命令的描述
Delete 向左删除一个字符
C-d 向右删除一个字符
M-Delete 向左删除一个单词
M-d 向右删除一个单词
C-k 删除到行末
M-k 删除到句末
C-SPC 或 C-@ 为选择模式,累死于vim的v,选择完成后C-w可以删除所选的内容
C-y 复制删除的内容
M-y 配合C-y使用,当删除多次时,选择复制删除的内容
M-w 复制所选的内容
C-/ 撤销操作
C-x 1 只保留光标所在的buffer
C-x 2 打开新的缓冲区
C-x C-b 列出缓冲区,emacs中,一个文件可以看完一个buffer
C-x C-c 关闭emacs
C-x s 保存多个buffer
M-x make-frame 打开新的窗口
M-x delete-frame 关闭选中的窗口
C-h m 查看当于使用的mode
M-x 切换major mode
C-s 向前搜索,配置了搜索内容之后,可以按Delete继续搜索,Enter结束搜索
C-r 向后搜索
3. build-in function
基本2中已经包含大部分内容
4. build-in function
学习elisp
通过切换到emacs的scrach buffer,可以执行elisp,把光标放在句末,C-x C-e可以即可执行以下为简短的演示
;; This buffer is for text that is not saved, and for Lisp evaluation.
;; To create a file, visit it with C-x C-f and enter text in its buffer.
(+ 2 2)
; 2 + 3 * 4
(+ 2 (* 3 4))
(setq my-name “sandwich”)
(message my-name)
(defun my-func ()
(interactive)
(message “hello, %s” my-name))
(my-func)
Mx my-func
(global-set-key (kbd “”) ‘my-func)
5. start to hack emacs
创建init.el
C-x C-f .emacs.d/init.el
保存
关闭工具栏
(tool-bar-mode -1)
不显示滚动条
(scroll-bar-mode -1)
调整缩进
electric-indent-mode -1)
关闭启动画面
(setq inhibit-splash-screen t)
设置f2打开配置文件
(defun open-my-init-file()
(interactive)
(find-file “~/.emacs.d/init.el”))
(global-set-key (kbd “”) ‘open-my-init-file)
(setq inhibit-splash-screen t)
显示最近打开文件
To be continued
将光标方块改为小竖条
(setq-default cursor-type ‘bar)
注意是setq-default不是setq
major mode & minor mode
major mode指每一种文件,都提供一种主要的编辑规则,一个文件只能有一个major mode
minor mode其它mode都为minor mode,一个文件可以有多个minor mode
6. package system
安装packge
点击Options-Manage Emacs Packages 可以打开package system。
点击company,再点击Install,即可安装company。
安装完的package保存在在 ~/.emacs.d/elpa 下。
company配置
company为complete anything,一个用于补全的package。
在init.el中加入(global-company-mode t),以后打开的文件都使用company mode。
7. other
org mode
org文件可以作为提纲,按tab可以展开关闭子内容。
to do
在heading中第一次C-c C-t可以将该事项设置为TO DO,第二次C-c C-t设置为DONE,第三次C-c C-t删除标识。
8. configuration
安装了company自动添加的配置和自己加上一配置,init.el为
;; Added by Package.el. This must come before configurations of
;; installed packages. Don’t delete this line. If you don’t want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
(package-initialize)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(electric-indent-mode -1)
(setq inhibit-splash-screen t)
(global-linum-mode t)
(defun open-my-init-file()
(interactive)
(find-file “~/.emacs.d/init.el”))
(global-set-key (kbd “”) ‘open-my-init-file)
(global-company-mode t)
(setq cursor-type ‘bar)
(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 (quote (company))))
(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.
)
本文介绍Emacs文本编辑器的基础操作及配置方法,包括安装、基本命令、内置函数使用、个性化配置及常用插件安装等,适合初学者快速上手。
573

被折叠的 条评论
为什么被折叠?



