Technical notes‎ > ‎

Using Emacs

Basic Emacs

Learn key combinations. C is for Control key (Ctrl) and M is for Meta (either Alt key or ESC key).
For example: C-x C-f (open file) means press and hold Ctrl key then press x, after that press f. Now you can release the Ctrl button and Emacs will prompt for file location.
For something like C-h i (to start Emacs' help), we press Ctrl key down and press h at the same time while still holding Ctrl key. After that, we release the Control key and press a single i key.

Before start

  1. Try not to touch your mouse.
  2. Download the cheat sheet at the end of this page.
  3. If you are stuck, press C-g to cancel whatever strange thing that is happening
  4. Press F10 to access menu, and then use arrow keys to navigate
  5. Make sure that you are running Emacs 24. It's great and free anyway!

Working with files and folders

  1. Open/close file(s)/switch between buffers (each buffer is one editing window. It can be a file or a temporary buffer such as *scratch* or a shell (terminal))
    1. Open: C-x C-f
    2. Close: C-x k (You don't really need to close buffers actually)
    3. Switch: C-x b
  2. Learn to use Dired mode (you can create/rename/move/delete multiple files and folders, etc.)
    1. When you C-x C-f a directory, you are in Dired mode. If you switch on ido-mode, navigate to a directory and press C-d to enter Dired mode.
    2. To copy files, mark the files with m and then press C (SHIFT+c) to copy. Emacs will prompt for destination.
    3. Delete files: press d to mark a file for delete. After you have marked all files, you press x to delete them.
    4. You also can delete files by marking them with m and then press D (SHIFT+d) to delete.
    5. To move files, mark the files with m and then press R (SHIFT+r) to copy. Emacs will prompt for destination. You can use this for rename (just move to the same folder with different name).
    6. If you delete/copy/rename/move a single file or folder, you don't need to mark them, just move to the file and then use D/C/R.
    7. Symlink a file/dir, press S.
    8. (de)compress file: Z
    9. Press F10 for menu and then see mark/oparate for more features.


  1. Learn navigation combinations (C-f / C-b for characters, M-f / M-b for words, C-p / C-n for lines). Why don't I use arrow keys instead? Because by using navigation combinations you don't need to move your hands away hence MUCH faster editing. You will appreciate this A LOT once you use to coding).
  2. Move to the beginning/end of the line: C-a / C-e
  3. Move to the beginning/end of the document: M-< / M-> (Press Alt and hold it while you press either < or > (SHIFT+, or SHIFT+. on a US keyboard)

Using Emacs help

  1. Emacs' help data is amazing, but it can be difficult to browse if we don't know how.
  2. To enable Emacs' help, use C-h i
  3. *info* buffer will be shown with the title "The Emacs Editor".
  4. If you are lost, press ? to see what can be done in this buffer.
  5. Different topics can be browsed by using "m". For example, we can press m, type "emacs" into the prompt "Menu item:" in the mini buffer (bottom left corner), and then press Enter. (emacs)top will be shown.
  6. We can use TAB key for suggestion. If you are in (emacs)top, try to press "m" key, and then enter "in", and then press TAB key. A list of topics that starts with "in" will be suggested. If we add "p" and then TAB again, "Input Methods" will be shown because there is only one topic that starts with "inp".
  7. To navigate around, use "n" and "p" to go to next/previous page. "^" to go to the parent page, and "d" to go to the top node (*info* top or The Info Directory).
    1. If you are in "Input Methods" page and press "n", you will go to "Select Input Method" page. From here, you can press "p" to go back to "Input Methods".


  1. C-x h to select all document (This also can be done with M-< C-SPACE M->)


  1. Copy/paste: C-SPACE to start marking mode. Navigate to the end of the part that you want to copy and then use C-w for cut and M-w for copy. C-y for paste.
  2. Undo: C-x u (There no need for redo because you can undo the undo hence redo). This is tricky, read this post to understand.
  3. Delete next character: C-d (I use this a lot)
  4. New line: C-j
  5. Delete until the end of line: C-k (So C-a C-k for kill the whole line). You can C-y the last killed lines. With this, you can come up with some cool combinations e.g. C-a C-k C-y C-j C-y for duplicate a line (Not that long if you think about it, just hold Ctrl and then press the sequence a-k-y-j-y) Once you are used to it you may type faster than you can even think.
  6. Learn to search and replace (C-s to activate search mode, type the word you want to start searching, press C-s to search for next instance). M-% is similar but for replace. (Press Alt and hold it while you press % (SHIFT+5 on a US keyboard)
  7. Shift a block right: C-u C-x [TAB] (or a number for n white-spaces)

Use shell:

  1. Press M-x and then type shell to use a built-in shell within emacs. You don't have to leave Emacs any more.
  2. Previous command / next command : M-p / M-n
  3. List command history C-c C-l
  4. See menu In/Out (F10) for more features

Language inputs

  1. M-x →"set-input-method" →ENTER →type in language of your choice →ENTER to set a language. (TAB can be used for suggestion, try vie →TAB or jap →TAB)
  2. C-\ to toggle language input

Software development

Lorem ipsum


Emacs as a Python IDE (elpy package)

  1. Install elpy: (follow the installation guide)
    First, install the required Python packages::
    # Run this command in terminal
    pip install rope jedi flake8 importmagic autopep8 yapf

    After Emacs started, press C-x b (Ctrl + X, release Ctrl and press b) to switch to *scratch* (~edit window). Paste this into in your *scratch* buffer (C-y for paste). Move the cursor to the end of the buffer and use C-x C-e to evaluate the command.

    (require 'package)
    (add-to-list 'package-archives
                 '("elpy" . ""))

    Now press M-x and then type package-refresh-contents and then press Enter (Return key) to load the contents of the new repository. After that press M-x and then type package-install [press Enter]  elpy  [press Enter] to install elpy.

    Finally, add the following to your .emacs:

  2. Configure elpy: Read more here:
  3. Install elpy manually. M-x > package-install-file. (elpy-1.14.1.tar is attached down below)
    1. Compiling Elpy:
      git clone
      cd elpy
    2. package-install-file the dist/elpy-x.x.x.tar
  4. Configuring flake8
    1. Create a file at ~/.config/flake8 (I tried ~/.flake8 and it worked on with Flake8 3.2.1 (pyflakes: 1.3.0, mccabe: 0.5.3, pycodestyle: 2.2.0) CPython 3.5.2 on Linux Fedora 24
    2. Add this code
      ignore = E402
    3. Read more about it at:


  1. Ctrl+x h to select all.
  2. Alt+x then untabify then ENTER (tab > space) or tabify (space > tab)
  3. Shift a block right: C-u C-x TAB
  4. Shift a block left (by 4 spaces): C-u -4 C-x TAB


  1. Force to activate python mode: M-x and then type python-mode and then press Enter
  2. C-c C-c to evaluate selected code
  3. C-c C-l to execute a file

Advanced topics

Org mode

Installing new mode

Compiling Emacs on Fedora

First, uninstall the pre-installed version of Emacs.

sudo dnf remove emacs

Extract the downloaded package. Install required packages

sudo dnf install libXpm-devel libjpeg-turbo-devel giflib-devel libtiff-devel ncurses-devel

Configure stuff


Install it

sudo make install (or make install prefix=/home/user/local/emacs-24.5)

Voila! Enjoy your self-compiled Emacs.
To update emacs to the latest version that we compiled, try this:

update-alternatives --install /usr/bin/emacs emacs /usr/local/bin/emacs-24.5 90
update-alternatives --set emacs /usr/local/bin/emacs-24.5

You can also

sudo make uninstall

To be updated.

Subpages (1): Emacs Lisp
Le Tuan Anh,
Mar 2, 2016, 5:42 AM
Le Tuan Anh,
Feb 1, 2017, 11:02 PM
Le Tuan Anh,
Nov 6, 2017, 1:24 AM