相關資源‎ > ‎

emacs

Emacs 是由 Richard Stallman 所開發,有內建的LISP Interpreter,是功能強大的編輯器
安裝Emacs
  • sudo apt-get install emacs
開啟說明檔
  • Built-in tutorial: C-h t
  • Info reader: C-h i
File Handling 指令
  • Open a file: C-x C-f    (Remote file: /user@host:path/to/file via ftp)
  • Change to a directory: C-x d
  • Save file: C-x C-s
  • Save as: C-x C-w
  • Close a file (kill buffer): C-x k
  • Reload file: C-x C-v
  • Change to another open file: C-x b
  • List all open files (buffers): C-x C-b
  • Maximize a window: C-x 1
  • Switch to the other window: C-x o
Editing 指令(編輯)
  • Start marking: C-<SPACE> (Use arrow keys to select region)
  • Cut: C-w
  • Copy: M-w
  • Paste: C-y (previous: M-y)
  • Undo: C-x u
  • Delete word: M-d
  • Complete word: M-/
  • Open a new line: C-o
  • Kill upto end of line: C-k (Is appended to clipboard)
  • Indent current line to GNU C standard: <TAB>
  • Toggle read-only: C-x C-q
  • Paragraph current region: M-q
  • Spell-check current word: M-$ (whole file: M-x ispell)
Search/ Replace 指令
  • Search forward: C-s (Press C-s to search again)
  • Search backward: C-r
  • Search and replace: M-%
  • List occurrences: M-x occur
  • Run grep: M-x grep
  • Reg-ex search: C-M-s
Navigation 指令
  • Beginning of file: M-<
  • End of file: M->
  • Beginning of line: C-a
  • End of line: C-e
  • Previous word: M-b
  • Next word: M-f
  • Previous matching bracket: C-M-b (if it doesn't work, try ESC followed by C-b)
  • Next matching bracket: C-M-f (or ESC C-f)
  • Outline mode: C-u 1 C-x $ (C-x $ to revert)
  • Go to line: M-g (or M-x goto-line).
  • Previous line: C-p
  • Next line: C-n
  • Previous character: C-b
  • Next character: C-f
  • Page Up: M-v
  • Page Down: C-v
Vertical Copy
  • Sometimes you will need to copy a vertical patch of data, e.g. one column in a table. First press C-<space> where you want to start copying. Then go to the end of the column and press C-x r k. To paste the column press C-x r y. (If you don't want to delete original column, just press C-_ there once to restore it and then press C-x r y at target.) 
Symbol Lookup with cscope
Download cscope program, and xcscope.el and cscope-indexer from an OSS repository. Save the xcscope.el onto some directory in Emacs' load-path. Edit your ~/.emacs as follows: (require 'xcscope) To add a directory ~/foo to your load-path, use the following directive in .emacs file, making sure it appears before the "require xcscope" directive: (setq load-path (cons "~/foo" load-path)) Place cscope-indexer in your $PATH. You can then use these keystrokes while browsing C source code:
    • Index files: C-c s I
    • Find global definition: C-c s d
    • Find symbol definition: C-c s s
    • Find this file: C-c s f
    • Find functions calling this function: C-c s c
    • Find functions called by this function: C-c s C
    • Find this pattern: C-c s e
    • Find this text string: C-c s t
    • Find files including this file: C-c s i

    Compiling and Debugging
    • Compile: M-x compile
    • Stop compilation: C-c C-k
    • Go to next error: C-x `
    • Go to source line giving the error: C-c C-c
    • Debug with GDB: M-x gdb
    • Insert breakpoint: C-x <SPACE>
    • Run a shell command: M-! (C-u M-! to insert output)
    • Open a shell: M-x shell
    Comparing Two Files
    • Start a diff session: M-x ediff
    • Next match: n
    • Previous match: p
    • Copy from file A to B: a
    • Copy from file B to A: b
    • Save file X: wX
    • See diff output: D
    • Ignore whitespace differences: ##
    • Compare directories: M-x ediff-directories
    Keyboard Macros
    • Begin recording: C-x (
    • End recording: C-x )
    • Execute macro: C-x e
    • Example: Add 'extern' before all function protoypes in a file. Go to the first prototype, and say:
    • C-x ( C-a extern<SPACE> C-n C-x ) Then say C-u 50 C-x e to replace 50 prototypes. 
    Dired
    Operations such as move, copy, delete etc. are available in the directory editor: M-x dired 
    Comments