Table of Contents

1 buffer

  • list-face-displays
  • fill-region
  • count-matches

2 Getting Help

  • describe-key-briefly: defaults to C-h c, return the command name of a key stroke.
  • where-is: defaults to C-h w, return the current shortcut for a command
  • info: defaults to C-h i, open the built-in info reader.
  • view-echo-area-messages

3 Configuration

To configure a specific key map. Note that the global-set-key will not overwrite a specific key map, because the specific one has a higher priority.

(define-key org-mode-map (kbd "C-j") (lambda()
                                       (join-line -1)))

Package installation is done by the built-in package management. Be sure to add it into the start script to be able to automatically install it for a new build of emacs.

  • list-package: open the package page. Use U x to update all available.

4 Window and Frame

4.1 window manage

  • balance-window
  • toggle-window-split
  • enlarge-window
  • shrink-window

4.2 dired

  • dired-next-subdir
  • dired-prev-subdir
  • dired-tree-up
  • dired-tree-down

4.3 packages

In *package* buffer, Ux to update all packages.

5 File Operation

Replace current buffer text with the text of the visited file on disk. I.e. Reload file.
recover from #xxx# file.
disable it to edit read only files

6 Editing

6.1 text transformation

  • replace-rectangle
  • upcase-word
  • downcase-word
  • transpose-words
  • transpose-lines

To insert a control sequence, use C-q xxx.

  • capitalize-word
  • fill-paragraph (M-q)
  • fill-region
  • auto-fill-mode

When replace-string, use C-q C-j to represent newline.

6.2 killing

  • zap-to-char
  • zap-up-to-char

6.3 spell checking

Use ispell, and flycheck to check on-the-fly. Check emacs manual for detail.

6.4 Replace regexp for multiple files inside project

  1. find-name-dired, select the root directory, and provide a pattern for files
  2. press t to toggle mark all files
  3. press Q for query and replace in files, and provide regexp and replacement
  4. proceed each of the match by: SPC to confirm, and n to skip to next.
  5. Finally all files are not saved. To save that, C-x s will prompt all file and wait for your confirm by y. To avoid hitting y many times, use C-x s !.

7 Programming

  • checkdoc: check the warnings in doc string. It can also fix it: C-h f.
  • C-x C-e: evaluate
  • C-u C-x C-e: evaluate and insert result

8 Moving

Defun movement:

move to the beginning of defun
move to the end of defun
mark defun
evaluate defun

Sexp movement

move forward a sexp
move backward a sexp
kill a sexp
mark following sexp
move to the next sexp
move to the previous sexp


transpose expressions
move up parenthesis
move down parenthesis

9 Navigating

  • forward-sexp: forward semantic block
  • backward-sexp
  • org-forward-heading-same-level: C-c C-f
  • org-backword-heading-same-level: C-c C-b

9.1 marking

  • exhange-point-and-mark
  • mark-word
  • mark-sexp
  • mark-paragraph
  • mark-defun
  • mark-page
  • mark-whole-buffer
  • point-to-register: save ppposition in a register
  • jump-to-register
  • set-mark-command: C-SPC, set mark, and activate it
  • C-SPC C-SPC: set mark, but not activate it.
  • C-u C-SPC: pop to previous mark in mark ring. current is stored at the end of mark ring(rotating)
  • pop-global-mark: will store both position and buffer

All events that set the mark:

  • C-w
  • search

9.2 register

  • jump-to-register: the register can store a file
  • copy-to-register
  • insert-register

9.3 Tags

  • helm-etags-select

10 Special Modes

10.1 Tex Mode

  • tex-validate-region

11 Variables

11.1 File Local Variable

On first line, emacs will try to find

-*- mode: Lisp; fill-column: 75; comment-column: 50; -*-=

mode defines the major mode for this file, while unlimited numbers of variables follows, separated by ; Emacs looks for local variable specifications in the second line if the first line specifies an interpreter, e.g. shebang.

A second way to specify file local variable is to have a "local variables list" near the end of the file (no more than 3000 characters from the end of the file). The Local Variables: and End: will be matched literally.

This     /* Local Variables:  */
Is       /* mode: c           */
Garbage  /* comment-column: 0 */
Data     /* End:              */

11.2 Directory Local Variable

Put .dir-locals.el at the root directory, and it will be in effect for all the files under that directory, recursively. It should be an associate list, the car can be either a mode name (or nil applies to all modes) indicating the variables are for that mode, or a sub-directory name to apply only in that directory.

((nil . ((indent-tabs-mode . t)
         (fill-column . 80)))
 (c-mode . ((c-file-style . "BSD")
            (subdirs . nil)))
  . ((nil . ((change-log-default-name
              . "ChangeLog.local"))))))

12 Advanced Topics

12.1 Info

Info is a document system. It is closely bundled with emacs, so I put it here. To install some new info document in the system, issue the following commands (using gnu-c-manual as an example):

# download the gnu-c-manual code
make gnu-c-manual.info
mv gnu-c-manual.info /usr/local/share/info
cd /usr/local/share/info
sudo install-info --info-file=gnu-c-manual.info --info-dir=.

12.1.1 Operations

key description
SPC page down, can cross node
BACKSPACE page up, can cross node
M-n clone-buffer, create a new independent info window
n next node on same level
p previous
] next node regardless of level
[ previous
u up node
l back
r forward
m Info-menu, convenient for search node title
s TODO search a text in the whole info file
i TODO search indices only

12.2 Babel

How to write a ob-xxx.el file?

some good example to look at: ob-plantuml.el, ob-C.el

13 Reference

Sacha's super long Emacs Config: http://pages.sachachua.com/.emacs.d/Sacha.html Some emacs.d I started with https://github.com/jordonbiondo/.emacs.d/blob/master/init.el C++ IDE and some tutorials: http://tuhdo.github.io/

Author: Hebi Li

Created: 2017-04-10 Mon 20:56