Emacs始终是我用得最舒服的文本编辑器,无论是在Windows下还是Linux,同时也是最让人抓狂的编辑器,很矛盾。
Windows下的Emacs(或者叫Emacs NT)从版本22开始,其配置文件.emacs.el(以前是.emacs)的默认位置改成了“C:/Documents and Settings/你的Windows用户名/Application Data/”;另外需要注意的是,WinXP下新建的文件不能是“.”开头,而且把文件改名(右键->重命名)也不可以改成“.”开头,解决办法就是随便新建个名字合法的文件,写入你的emacs配置,保存,然后在DOS窗口里面用COPY命令另存为.emacs.el。
这是我正在使用的.emacs.el,很久前抄来的,删掉了一些版本22里面不支持的条目,另外一些require第三方库的配置应该也是失效的,懒得删了,能用就行:
;; .emacs.el
;;; uncomment this line to disable loading of "default.el" at startup
;; (setq inhibit-default-init t)
;; turn on font-lock mode
(global-font-lock-mode t)
;; enable visual feedback on selections
(setq transient-mark-mode t)
;; (setq visible-bell t)
(setq inhibit-startup-message t)
(setq column-number-mode t)
(setq kill-ring-max 200)
(setq enable-recursive-minibuffers t)
(setq scroll-margin 0
scroll-conservatively 100000)
(setq default-major-mode 'text-mode)
(show-paren-mode t)
(setq show-paren-style 'parentheses)
(mouse-avoidance-mode 'animate)
(setq frame-title-format "emacs@%b")
(auto-image-file-mode)
(require 'iswitchb)
(iswitchb-default-keybindings)
;;; some key-bindings
(global-set-key (kbd "C-x <SPC>") 'set-mark-command)
;;; shift the meaning of C-s and C-M-s
(global-set-key [(control s)] 'isearch-forward-regexp)
(global-set-key [(control meta s)] 'isearch-forward)
(global-set-key [(control r)] 'isearch-backward-regexp)
(global-set-key [(control meta r)] 'isearch-backward)
;;; jka-compr -- read compressed files directly
(require 'jka-compr)
(jka-compr-install)
(add-hook 'write-file-hooks 'time-stamp)
(setq time-stamp-format "%:u %04y-%02m-%02d %02H:%02M:%02S")
(display-time)
因为不懂LISP语法,所以只能是照抄别人的然后自己拼凑一下。这个配置文件大概做了下面几点:
- 启动的时候不显示那个GNU图片,状态栏那里显示行号列号和当前时间
- 区域选择的时候高亮显示
- 括号匹配时高亮显示括号
- 编辑光标和鼠标重叠时,自动把鼠标指针拿开
- 向下滚屏改成一次只滚一行而不是默认的一屏
- 把开始区域选择的组合键改成“c-x space”,默认是“c-space”或“c-@”,前者和激活中文输入法的快捷键冲突,后者不好按
常用组合键备忘:
- 打开文件/目录:c-x c-f
- 保存:c-x c-s,保存全部:c-x s,关闭文件:c-x k
- 光标移动到行末:c-e,移动到行开头:c-a,移动到文末:m->,移动到文章开头:m-<,移动到下一行:c-n,移动到上一行:c-p,移动到下一屏:c-v,移动到前一屏:m-v(这两个太不顺手了,要自定义一下才好);c-l,把光标所在行定位到屏幕中间
- 区域选择开始:c-x space,复制:m-w,剪切:c-w,粘贴:c-y
- c-y m-y,粘贴kill-ring里面的上一个文本记录,再按一次m-y粘贴再上一次的记录,如此循环
- c-k,删除从光标到行末的全部内容
- c-s,向后搜索,支持正则表达式,不断重复按c-s,则不断跳到下一个匹配的;c-r是向前搜索
- c-/,undo
- c-x b,看看都打开了那些文件,切换到想要的文件buffer
- c-x 2,水平分割窗口;c-x o,在窗口间切换;c-x 0,关闭当前的分割窗口,c-x 1将当前分割的窗口占满整个屏幕
- dired-mode下的常用文件操作:m,标记文件,u取消标记,g刷新目录,f打开文件或进入目录,R文件改名(也可用来移动文件),D删除文件,+创建目录,C复制文件;其他组合键也可在dired-mode下使用,比如c-s、c-n之类