2016年12月30日 星期五

Emacs 常用指令

使用Console mode進入Emacs: emacs -nw [filepath]

=========安裝plugin==========

列出可用套件  package-list
安裝套件     package-install

=========移動================

M->     移動至文件最後一行
M-<     移動至文件開頭

=========基本說明================

C-   按住 Ctrl      鍵
M-   按住 Meta      鍵 (the Alt key)
S-   按住 Shift     鍵 (‘S-TAB’ means Shift Tab)
DEL  按住 Backspace 鍵 (not the Delete key)
RET  按住 Enter     鍵
SPC  按住 空白       鍵
ESC  按住 Esc       鍵
TAB  按住 TAB       鍵

M-x          進入指令輸入模式</td></tr>
C-g          取消指令或快捷鍵 (當按錯鍵時,一直按C-g取消就對了)</td></tr>
C-Shift-_    還原操作,也就是windows的C-z</td></tr>
M-x ido-mode 進入ido-mode,所有指令都會有交戶提示,真是太棒了

==========求救==================

C-h m   "describe-mode"           查看目前buffer的所有key binding及major & minor mode說明
C-h w   "where-is"                查看某個command對應的快捷鍵
C-h c   "describe-key-briefly"    查看某快捷鍵對應的command,例如你按完C-h c後再按C-x C-f 就能查詢C-x C-f的對應command
C-h k   "describe-key"            察看某快捷鍵的完整功能說明,是C-h c的加強版,使用C-h k 你就知道某指令該如何使用
C-h e   "view-echo-area-messages" 查看logging訊息
C-h v   "describe-variable"       察看某個變數的定義
C-h C-h "help-for-help"
M-x man                           Get a UNIX manual page and put it in a buffer.

=========檔案操作================

C-x C-f                           開新檔案
C-x C-s                           儲存檔案
C-x C-c                           離開Emacs
C-x C-w                           另存新檔
M-x dired                         打開檔案瀏覽器
M-x find-file-other-window        打開檔案瀏覽器,可用方向鍵選取檔案後,按下enter開啟檔案
M-x find-file-at-point            打開header file


=========視窗操作================

C-x 0       關閉目前視窗
C-x 1       關閉目前以外所有視窗
C-x 3       將目前視窗分割成左右兩半
C-x 2       將目前視窗分割成上下兩半
C-x k       刪除buffer
C-x o       切換至其他視窗
C-x C-b     打開buffer管理器
C-x C-b g   打開buffer管理器,輸入g會刷新buffer列表視窗
C-x C-b d   打開buffer管理器,輸入d會標注該buffer為即將刪除
C-x C-b x   打開buffer管理器,執行刪除操作
C-x C-b q   離開buffer管理器

=========反白、複製、貼上==========

C-@         反白
C-x h    全選
M-w         複製
C-y         貼上


C-k         刪除一行
M-d         向後刪除一個word
M-BACKSPACE 向前刪除一個word
M-\         刪除目前位置的空白
M-;         註解一行或選取區域的多行
M-/         自動補齊

=========搜尋=================

C-s         "isearch-forward"  向後搜尋
C-r         "isearch-backward" 向前搜尋
M-C-s                       正規表示式搜尋
C-s C-w                        搜尋游標所在的字串
M-s o                          開啟*Occur*,搜尋特定字串,並列出所有符合該字串的行號
M-x rgrep                      搜尋專案底下所有檔案,列出含有該關鍵字的檔案及行號

M-.    "ggtags-find-tag-dwim"  找到目前function定義或reference處
M-,    "pop-tag-mark"          跳回先前位置
=========設定書籤=================

C-x r m "bookmark-set"         設定書籤,以後可以用C-x r b或來C-x r l來跳到特定位置
C-x r l "bookmark-bmenu-list"  打開書簽列表
C-x r b "bookmark-jump"        跳到指定書簽

A few useful key bindings when in bookmark-bmenu-list:
RET Open a bookmark.
  After you opened the bookmark, you can go back to bookmark list
  by C-x r l.
1 Open a bookmark and close other buffers
n Go to next entry
p Go to previous entry
s Save the current bookmark list to file.
o Open bookmark in other window and move point to it. If you
  want to view side by side, C-x 3 to create a vertical buffer
  and bookmark will be opened in the vertical buffer.
C-o Similar to o but point remains on the bookmark list.
r Rename bookmark at point.
m Mark bookmark at point for displaying.
v Display all marked bookmarks.
d Flag bookmark for deletion.
x Delete flagged bookmarks.
u Unmark marked or flagged bookmarks.


=========C語言相關操作=================

C-M-f "forward-sexp"   向後尋找右括號
C-M-b "backward-sexp"  向前尋找左括號
C-M-k "kill-sexp"   刪除成對括號


C-M-a  "beginning-of-defun" 移動至function開頭
C-M-e  "end-of-defun"       移動至function結尾
C-M-h  "runs mark-defun"    反白目前的function
M-.    "ggtags-find-tag-dwim" 找到目前function定義
M-,    "pop-tag-mark"       跳回先前位置


(define-key ggtags-mode-map (kbd "C-c g s") 'ggtags-find-other-symbol)
(define-key ggtags-mode-map (kbd "C-c g h") 'ggtags-view-tag-history)
(define-key ggtags-mode-map (kbd "C-c g r") 'ggtags-find-reference)
(define-key ggtags-mode-map (kbd "C-c g f") 'ggtags-find-file)
(define-key ggtags-mode-map (kbd "C-c g c") 'ggtags-create-tags)
(define-key ggtags-mode-map (kbd "C-c g u") 'ggtags-update-tags)
(add-to-list 'company-c-headers-path-system "/usr/include/c++/4.8/")


C-c C-j "semantic-ia-fast-jump" 跳到對應的header檔
global-semantic-idle-summary-mode 再下方的mini buffer顯示function的definition
M-x compile 可以下comile的指令

ggtags用來找自己專案的function定義
complete-semantic 用來自動complete
semantic-add-system-include 用來加入標頭檔路徑
semantic-force-refresh 強制semantic更新
sr-speedbar 用來展示.c檔的樹狀結構
senator 用來折疊function,和跳入下一個function