EMACS使用
通过前一段时间EMACS的使用,我深深的被这个编辑器所吸引,EMACS实在是太强大了,无论是代码编辑、自 动插入、自动补全、代码阅读,实在是太好用了,现将我的EMACS配置文件分享给大家http://sites.google.com/site /ideaofanima/附件里是我的全部配置文件
EMACS常用快捷键
M-x replace-string
C-q
C-m
去掉文件中的^M
C-c C-n是Next line,C-c C-s是step in
C-f9 启动shell
C-X h全选
C-M-\ : 对选中区域,按照某种格式(比如C程序)进行格式化
M-跳转到文件尾
C-M-f和C-M-b在匹配括号间跳转
M-g-g跳转到指定行
跳转到其他窗口M-o
C-/ 撤销
C-. 重做
C-x } 调整窗口大小
C-x r m 添加书签
C-x r b 跳到某个书签
M-x list-bookmarks 显示所有书签,在里面d标记删除,u取消,r重命名,x执行操作
常用EMACS编辑命令
C-f 向右移动一个字符
C-b 向左移动一个字符
M-f 向右移动一个词【对中文是移动到下一个标点符号】
M-b 向左移动一个词【对中文是移动到上一个标点符号】
C-n 移动到下一行
C-p 移动到上一行
C-a 移动到行首
C-e 移动到行尾
C-g 退出当前命令
C-s 增量向前搜索
C-, 复制当前单词
C-k 删除光标至行末
C-S-backspace 删除当前行
C-Backspace 删除单词
C-d 删除字符
C-y 粘贴
C-w 剪切
M-w 复制
C-x r k 删除矩形区块
C-x r t 用指定字符填充矩形区块
C-c s a 设定初始化的目录,一般是你代码的根目录
C-s s I 对目录中的相关文件建立列表并进行索引
C-c s C-h 查看所有的 cscope 相关的按键
C-c s a 设定索引文件所在目录
C-c s c 查找调用该函数的地方
C-c s g 查找该符号的全局定义
C-c s f 查找该符号对应的文件
我的EMACS配置文件
(add-to-list ‘load-path “~/.emacs.d/”)
(setq x-select-enable-clipboard t);
;;set the color-theme
(require ‘color-theme)
(color-theme-deep-blue)
(global-set-key “\M-’” ‘set-mark-command)
(global-set-key “\M-r” ‘replace-string)
(add-hook ‘c-mode-common-hook
‘(lambda()
(require ‘xcscope)))
;;auto add code
(load “~/.emacs.d/smart-edit/auto-insert.el”)
;;auto redo
(load “~/.emacs.d/redo.el”)
(global-set-key (kbd “C-.”) ‘redo);重做
;;smart-compile
(load “~/.emacs.d/smart-compile/c-compile.el”)
(global-set-key (kbd “C-x C-b”) ‘electric-buffer-list)
(global-set-key (kbd “M-o”) ‘other-window)
;(global-set-key (“M-n”) ‘gnus)
;; 启动新闻组客户端 gnus。
(setq-default kill-whole-line t)
;; 在行首 C-k 时,同时删除该行。
(show-paren-mode 1) ; 高亮显示匹配的括号。
(require ‘saveplace)
(setq-default save-place t)
(desktop-save-mode 1)
(load-library “multi-gud.el”)
(load-library “multi-gdb-ui.el”)
;; 给每行显示行号
(require ‘linum)
(global-linum-mode t)
;;自动补全括号
(defun my-c-mode-auto-pair ()
(interactive)
(make-local-variable ‘skeleton-pair-alist)
(setq skeleton-pair-alist ’(
(?` ?` _ “””)
(?\( ? _ ” )”)
(?\[ ? _ " ]“)
(?{ \n > _ \n ?} >)))
(setq skeleton-pair t)
(local-set-key (kbd “(“) ‘skeleton-pair-insert-maybe)
(local-set-key (kbd “{“) ‘skeleton-pair-insert-maybe)
(local-set-key (kbd “`”) ‘skeleton-pair-insert-maybe)
(local-set-key (kbd “[") 'skeleton-pair-insert-maybe))
(add-hook 'c-mode-hook 'my-c-mode-auto-pair)
(add-hook 'c++-mode-hook 'my-c-mode-auto-pair)
;;输入左边的括号,就会自动补全右边的部分.包括(), "", [] , {} , 等等。
(fset ‘yes-or-no-p ‘y-or-n-p)
(setq frame-title-format “%f”)
(column-number-mode t)
(transient-mark-mode t)
(show-paren-mode t)
(tool-bar-mode -1)
(set-clipboard-coding-system ‘ctext)
(set-scroll-bar-mode nil) ; no scroll bar, even in x-window system
;;;; 关闭启动画面
(setq inhibit-startup-message t)
;; 代码折叠:
(load-library “hideshow”)
(add-hook ‘c-mode-hook ‘hs-minor-mode)
(add-hook ‘c++-mode-hook ‘hs-minor-mode)
(add-hook ‘java-mode-hook ‘hs-minor-mode)
(add-hook ‘perl-mode-hook ‘hs-minor-mode)
(add-hook ‘php-mode-hook ‘hs-minor-mode)
(add-hook ‘emacs-lisp-mode-hook ‘hs-minor-mode)
;; 快速切换到 shell 并 cd 到当前 buffer 所在的目录
(defun kid-switch-to-shell ()
(interactive)
(when (null (cdr (window-list)))
(split-window-vertically))
(let ((file buffer-file-name))
(other-window 1)
(shell)
(when file
(end-of-buffer)
(when (looking-back shell-prompt-pattern)
(insert “cd ” (file-name-directory file))
(call-interactively ‘comint-send-input)))))
(global-set-key (kbd “”) ‘kid-switch-to-shell)
;;auto insert
(global-set-key (kbd “M-/”) ‘hippie-expand)
(setq hippie-expand-try-functions-list
‘(try-expand-dabbrev ; 搜索当前 buffer
try-expand-dabbrev-visible ; 搜索当前可见窗口
try-expand-dabbrev-all-buffers ; 搜索所有 buffer
try-expand-dabbrev-from-kill ; 从 kill-ring 中搜索
try-complete-file-name-partially ; 文件名部分匹配
try-complete-file-name ; 文件名匹配
try-expand-all-abbrevs ; 匹配所有缩写词
try-expand-list ; 补全一个列表
try-expand-line ; 补全当前行
try-complete-lisp-symbol-partially ; 部分补全 elisp symbol
try-complete-lisp-symbol)) ; 补全 lisp symbol
(require ‘uniquify)
(setq uniquify-buffer-name-style ‘forward)
;;;;高亮当前行
(require ‘hl-line)
(global-hl-line-mode t)
;;;;导入CEDET的各个插件
;; —————————————
;; Load CEDET
(load-file “~/.emacs.d/cedet-1.0pre6/common/cedet.el”)
;; Enabling various SEMANTIC minor modes. See semantic/INSTALL for more ideas.
;; Select one of the following
(semantic-load-enable-code-helpers)
;; (semantic-load-enable-guady-code-helpers)
;; (semantic-load-enable-excessive-code-helpers)
;; Enable this if you develop in semantic, or develop grammars
;; (semantic-load-enable-semantic-debugging-helpers)
; ctrl+;: 代码折叠
(global-set-key (kbd “”) ‘hs-toggle-hiding)
;; —————————————
;;配置session
(add-to-list ‘load-path
“~/.emacs.d/session/lisp”)
(require ‘session)
(add-hook ‘after-init-hook ‘session-initialize) ;; 启动时初始化session
;; —————————————
;;;; 配置 Emacs Code Browser
(add-to-list ‘load-path
“~/.emacs.d/ecb-2.40/”)
(require ‘ecb)
;; —————————————
(global-set-key [f12] ‘ecb-activate) ;;定义F12键为激活ecb
(global-set-key [C-f12] ‘ecb-deactivate) ;;定义Ctrl+F12为停止ecb
(setq ecb-tip-of-the-day nil)
;; —————————————
;;;;配置Sementic的检索范围
(setq semanticdb-project-roots
(list
(expand-file-name “/”)))
(defun my-indent-or-complete ()
(interactive)
(if (looking-at “\\>”)
(hippie-expand nil)
(indent-for-tab-command))
)
;; —————————————
(global-set-key [(control tab)] ‘my-indent-or-complete)
(global-set-key [(tab)] ‘my-indent-or-complete)
(global-set-key [(meta ?/)] ‘semantic-ia-complete-symbol-menu)
(global-set-key [(meta return)] ‘semantic-ia-complete-symbol-menu) ;;设置Alt+Enter为自动补全菜单
;; —————————————
(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.
‘(ecb-options-version “2.40″))
(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.
)
;; —————————————
(require ‘windmove)
(global-set-key [M-left] ‘windmove-left)
(global-set-key [M-right] ‘windmove-right)
(global-set-key [M-up] ‘windmove-up)
(global-set-key [M-down] ‘windmove-down)
;; —————————————
(add-hook ‘c-mode-common-hook ( lambda() ( c-set-style “k&r” ) ) ) ;;设置C语言默认格式
(add-hook ‘c++-mode-common-hook ( lambda() ( c-set-style “k&r” ) ) ) ;;设置C++语言默认格式
(setq c-basic-offset 2)
(setq show-paren-style ‘parentheses) ;;
(global-set-key [?\S- ] ‘set-mark-command) ;;
(global-set-key [(f4)] ‘speedbar)
;shell,gdb退出后,自动关闭该buffer
(add-hook ‘shell-mode-hook ‘mode-hook-func)
(add-hook ‘gdb-mode-hook ‘mode-hook-func)
(defun mode-hook-func ()
(set-process-sentinel (get-buffer-process (current-buffer))
#’kill-buffer-on-exit)
)
(defun kill-buffer-on-exit (process state)
(message “%s” state)
(if (or
(string-match “exited abnormally with code.*” state)
(string-match “finished” state))
(kill-buffer (current-buffer))))
(global-set-key [(f6)] ‘gdb)
(setq gdb-many-windows t)
;;Calendar 中显示农历节日
(load “~/.emacs.d/chinese-calendar.el”)
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/99841/showart_1981496.html

