天天看點

轄vim之威學習emacs-基礎篇(快捷鍵比較)

----------------------------------------

轄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-]            

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/