----------------------------------------
辖vim之威学习emacs
----------------------------------------
emacs 入门还是需要看入门,指南一类的文档,自带的文档就非常好,ctrl-h 有完整的帮助。
网上也有很多快捷键,使用入门类文章。
有一定基础后,就要不断的进行实战来提高了。
借助自己已经掌握的vim技巧来迅速提高emacs技巧的笔记
1. 查询man-page
emacs: M-x manual-entry RET unix-command-name RET
vim: K
2. 执行shell 命令并读入输出到光标处
emacs: C-u M-! shell-command
vim: r !shell-command
例如我常读入shell date的输出添加到文档中
3. 重复参数
emacs: M-n or C-u n
vim: n
例如输入40个-字符
4. 自动完成输入
emacs: M-/
vim: C-f 及 C-n
5. 合并两行
emacs: M-^
vim: J
6. 插入空行
emacs: C-o C-O C-J C-e<RET>
vim: o O
7. 位置register 的使用(请正确理解意思)
emacs: C-x r SPC r --> C-x r j r
emacs 加书签: Alt-x bookmark
vim: mr --> 'r mA --> 'A
8. 简写功能:
emacs Alt-x abbrevate
vim :abbrevate
----------------------------------------
c程序员的扩展功能比较
----------------------------------------
emacs: vim 说明
M-C \ = 缩进
M-m ^ 光标移动到第一个非空字符上
M-^ J 合并两行
M-x comment-region
M-x kill comment-region
M-C-a [[ 移动到函数头
M-C-e [] 移动到函数尾
M-C-h C-v 标记函数
C-c C-u ]# 移动到上一个预处理条件
C-c C-d [# 移动到下一个预处理条件
M-; 添加注释
etags: ctags(taglist)
M-. C-]
M-, C-t
C-x 4 . :ptags
M-x tags-search
M-x list-tags RETURN taglist插件 显示文件tag
--------------------------------------------------------------------------------
语言使用特征比较
--------------------------------------------------------------------------------
C-h v RETURN load-path :set runtimepath? emacs 的加载路径:
M-x: describing-coding-system :set file-encoding? 查看编码格式
M-x: revert-buffer-with-coding-system :e ++enc=xxxx 以指定的编码格式重新加载文件
M-x: set-buffer-file-coding-system :set file-encoding=xxx 转换缓存中的文件编码格式,这样存盘是编码就改变了.
加载其它文件
(require 'name) source name.vim
(load "name.el)
自动运行命令
(addhook 'c++-mode-hook autocmd BufRead *.cpp :call fun
'(lambda() ...))
绑定快捷键
(global-set-key cmd 'fun) nmap <silent> <F8> :call fun<CR>
(define-key c++-mode-map imap <F9> :call fun<CR>
(kbd "c-\") 'fun)
-----------------------------------------------------------------
emacs 与 vim 命令对比(网上摘录)
-----------------------------------------------------------------
exit: C-x C-c :qa /:wq /:xa /:q!
Get back/command mode: C-g <esc>
Backward(left): C-b h
Forward(right): C-f l
Next(down): C-n j
Previous(up): C-p k
stArt of line(^): C-a 0
End of line($): C-e $
mUltiple commands: C-u nnn cmd nnn cmd
Multiple commands: M-digitkey cmd
save File: C-x C-s :w
beginning of buffer: M-< 1G
end of buffer: M-> G
scroll forward 1 screen: C-v ^F
scroll forward 1/2 screen: ^D
scroll forward 1 line: ^E
scroll backward 1 screen: M-v ^B
scroll backward 1/2 screen: ^U
scroll backward 1 line: ^Y
scroll the other window: M-C-v
delete under cursor: C-d x
delete from cursor to eol: C-k D
iSearch forward: C-s
isearch Reverse: C-r
Search forward: C-s enter /
search Reverse: C-r enter ?
isearch regexp: M-C-s
isearch backward regexp: M-C-r
search regexp: M-C-s enter /
search backward regexp: M-C-r enter ?
Help: C-h C-h :help
Help Apropos: C-h a
Help key Bindings: C-h b :help [key]
Help Info: C-h i
Help Major mode: C-h m
Help tutorial: C-h t :help howto
Undo: C-_ u
Redo: C-f ^R
Mark cursor position: C-x r SPC m{a-zA-Z}
eXchange Mark and position: C-x C-x
goto mark in current file: C-x r j '{a-z}
goto mark in any file: '{A-Z}
copy region: M-w {visual}y
kill region: C-w {visual}d
Yank and keep buffer: C-y
Yank from kill buffer: M-y p
convert region to Upper: C-x C-u {visual}U
convert region to Lower: C-x C-l {visual}u
Insert special char: C-q octalnum/keystroke
^V decimal/keystroke
replace: M-x replace-string :%s/aaa/bbb/g
replace regexp: M-x replace-regexp :%s/aaa/bbb/g
query replace: M-% :%s/aaa/bbb/gc
query replace: M-x query-replace
query replace regexp: M-x query-replace-regexp
Open file: C-x C-f :r file
Save file: C-x C-s :w
Save all buffers: C-x s :wa
Save as: C-x C-w file :w file
Prompt for buffer: C-x b
List buffers: C-x C-b :buffers
Toggle read-only: C-x C-q :set ro
Prompt and kill buffer: C-x k
Split vertical: C-x 2 :split
Split horizontal: C-x 3 :vsplit (ver. 6)
Move to other window: C-x o ^Wp
Delete this window: C-x 0 :q
Delete other window(s): C-x 1 ^Wo
run shell in bg: M-x compile
kill shell run in bg: M-x kill-compilation
run make: :make Makefile
check error message: C-x` :echo errmsg
run shell and record: M-x shell :!script -a tmp
...clean BS, ... :!col -b <tmp >record
...save/recall shell record: C-x C-w record :r record
run shell: M-! sh :sh
run command: M-! cmd :!cmd
run command and insert: C-u M-! cmd :r!cmd
run filter: M-| file {visual}:w file
run filter and insert: C-u M-| filter {visual}:!filter
show option :se[t] {option}?
reset option to default :se[t] {option}&
reset boolean option :se[t] no{option}
toggle boolean option :se[t] inv{option}
wrap text at column 72 :se tw=72
do not wrap :se tw=0
autoindent :se ai
expand tab :se et
在多个文件中查找和替换.
下面只是意会,不是实际操作
把该目录下所有的cpp文件中origin 替换为 replace
emacs: 在dired 中操作
M-x find-name-dired *.cpp t Q <origin> <replace>
vim: 借助于命令行find 命令,用argdo在多个文件中查找替换.
vim `find . -name *.cpp" argdo! %s/origin/replace/