Emacs
Variants:
- GNU Emacs
- mg (used to be micro GNU Emacs), minimal OpenBSD fork
- Spacemacs, Emacs Distribution/Setup, for VIM-users
- ErgoEmacs, Keybindings by Xah Lee for better ergonomics
Tutorials:
- http://ergoemacs.org/emacs/emacs.html (Xah Lee: Practical Emacs)
Table of standard keybindings:
Good Packages
-
AucTeX https://www.gnu.org/software/auctex/ - Editing LaTeX, includes latex-preview
- ubuntu etc: sudo-apt get auctex
- Org-mode - Organize ideas and notes, planning, like vimwiki but has more of everything (built in)
- gnus - Email, Newsgroups, RSS (built in)
- notmuch - Email
- dired - directory editing mode (built in)
- Magit - git mode
First steps
Open from the terminal with emacs & or in your desktop menu. emacs --no-window-system or emacs -nw starts without the GUI, just in the terminal. If you want emacs to always start in the terminal, you can either install the emacs-nox package or just create a simple shell-alias.
General Interface stuff
Emacs is not a modal editor like VIM.
To Yank means to paste, like in VIM. Kill usually means to cut or copy.
C-x means to press Ctrl+x. M-x means to press Alt+x. The meta-key (M) is Alt by default, you can of course change it though. As a general guideline: the meta-version of a command is often a somewhat stronger version of C-. E.g. C-w is cut, M-w is copy.
Command | Keycombination |
---|---|
Undo | C-/ |
Redo | C-g, C-/ |
Save | C-x, C-s |
Quit | C-x, C-c |
Word forward | C-Right oder M-f |
Word back | C-Left oder M-b |
Document beginning | C-Home oder M-< |
Document end | C-End oder M-> |
Character forward | C-f |
Character back | C-b |
Page down | C-v, PgDown |
Page up | M-v, PgUp |
Delete right word | M-d |
Delete left word | M-Backspace |
Delete line | C-k |
Select text | C-Space |
Copy | M-w |
Cut | C-w |
Insert | C-y |
Abort Command/Sequence | C-g |
To select text, put the cursor on the beginning of the select-area, press C-Space, then go to the end of the select-area and perform your manipulation (e.g. copy),
Window Splits
Command | Keycombination |
---|---|
horizontal split | C-x, 2 |
vertical split | C-x, 3 |
next window | C-x, o |
delete other windows | C-x, 1 |
delete this window | C-x, 0 |
Input Methods
If your native tongue is German (or something similiar, it's not the only postfix language) but you usually use an English keyboard, it might be a good idea to automatically convert ae to ä and AE to Ä without changing the keyboard layout for every letter. To do this just press C-u C-\ and type german-postfix. After doing this you can switch between the layouts with C-\.
Configuration
The init-file is located in ~/.emacs (~/.mg for mg). You can immediately load changes in the file in an opened emacs session with M-x load-file.
Some examples:
;; ========ENCODING======== ;; UTF-8 as default encoding (set-language-environment "UTF-8") (set-default-coding-systems 'utf-8) ;; ========STYLE========== ;; load theme misterioso ;; (load-theme 'misterioso) ;; moe-theme (add-to-list 'custom-theme-load-path "~/.emacs.d/themes/") (load-theme 'moe-dark t) ;; set background color independent from theme ;;(setq initial-frame-alist ;; '((width . 92) ;; (height . 54) ;; (background-color . "honeydew"))) ;;(setq default-frame-alist ;; '((menu-bar-lines . 1) ;; (tool-bar-lines . 0) ;; (width . 92) ;; (height . 52) ;; (background-color . "honeydew"))) ;; default font and size ;; M-x (print (font-family-list)) to show fonts ;;(when (member "DejaVu Sans Mono" (font-family-list)) ;; (set-face-attribute 'default nil :font "DejaVu Sans Mono-10")) ;; show line numbers (global-display-line-numbers-mode 1) ;; turn on highlighting of current line for all files ;; toggle on/off with M-x for current buffer (global-hl-line-mode 1) ;; turn on bracket match highlight (show-paren-mode 1) ;; set line spacing ;;(setq line-spacing 0.5) ;; stop cursor blinking (blink-cursor-mode 0) ;; ======KEYBINDINGS===== ;; swapping Ctrl & Alt from within Emacs is not possible, ;; you have to do it from the OS and independently for each OS ;; =======EDITING======== ;; auto insert closing bracket (electric-pair-mode 1) ;; stop cursor between CamelCase words (global-subword-mode 1) ;; disable automatic backup~ files (setq make-backup-files nil) ;; disable #auto-save# files ;; (setq auto-save-default nil) ;; refresh file automatically if it changes ;;(global-auto-revert-mode 1) ;; keep list of recently opened files ;; to use press M-x recentf-open-files, then just press digit key (require 'recentf) (recentf-mode 1) (setq recentf-max-menu-items 25) (global-set-key "\C-x\ \C-r" 'recentf-open-files) ;; remember cursor position - return cursor to same position ;; if file is opened again (if (version< emacs-version "25.0") (progn (require 'saveplace) (setq-default save-place t)) (save-place-mode 1))
Default Keybindings
People sometimes ask me if it is a sin in the Church of Emacs to use vi. Using a free version of vi is not a sin; it is a penance. So happy hacking. -- Richard Stallman
Moving
Command | Keycombination | Remember |
---|---|---|
Character forward | C-f | forward |
Word forward | M-f oder C-Right | forward |
Character backward | C-b | back |
Word backward | M-b oder C-Left | back |
Page down | C-v, PgDown | Arrow down |
Page up | M-v, PgUp | |
Document beginning | C-Home | Stronger Home |
Document end | C-End | Stronger End |
Cursorpos. becomes screencenter | C-l | |
Line down | C-n | next line |
Line up | C-p | previous line |
Statement end | M-e | end |
Line end | C-e | end |
Statement start | M-a | Anfang (German for start) |
Line start | C-a | Anfang |
Command | Keycombination | Remember |
---|---|---|
recently opened files | M-x recentf-open-files | |
C-x C-r | if set in .emacs | |
File open | C-x C-f | find file |
File save | C-x C-s | save |
File save as | C-x C-w | write |
Open menu | [F10] | also in -nw mode! |
Command | Keycombination | Remember |
---|---|---|
Buffer list | C-x C-b | buffer |
Buffer choose | C-x b | buffer |
Buffer close | C-x k | kill |
Command | Keycombination | Remember |
---|---|---|
Shell open | M-x shell |
Buffermanipulation
Copy/Paste
Command | Keycombination | Remember |
---|---|---|
Undo | C-/ | |
Redo | C-g, C-/ | Abort command: undo |
Cut | C-w | wipe |
Copy | M-w | stronger C-w |
Paste | C-y | yank |
Delete
Command | Keycombination | Remember |
---|---|---|
Character delete | C-d | delete char |
Word delete right | M-d | delete word |
Word delete left | M-Backspace | |
Line delete | C-k | kill line |
Sentence delete | M-k | kill sentence |
Search/Replace
Command | Keycombination | Remember |
---|---|---|
Word search | C-s | search |
next occurence | C-s again | |
prev. occurence | C-r | redo search |
Search end | C-g | abort command |
Replace all | M-x replace-string | replaces all |
Replace some | M-% | asks every time if you want to replace |
Splits
Not finished yet.
Tips
trailing whitespace: whitespace/spaces after the last non-whitespace character in a line
Delete trailing whitespace with M-x delete-trailing-whitespace for the whole buffer.
LaTeX
Install the package AucTeX with your package manager and activate it by adding
;; ========LATEX========= ;; output pdf files (setq TeX-PDF-mode t) ;; various options (setq TeX-auto-save t) (setq TeX-parse-self t) (setq-default TeX-master nil) (TeX-insert-braces 1) ;; visual line mode (add-hook 'LaTeX-mode-hook 'visual-line-mode) ;; on-the-fly spell checking ;; (add-hook 'LaTeX-mode-hook 'flyspell-mode) ;; math mode (add-hook 'LaTeX-mode-hook 'LaTeX-math-mode) ;; AUCTeX package (load "auctex.el" nil t t) (load "preview-latex.el" nil t t) (require 'tex-site) ;; RefTeX package (integrated) (require 'reftex) (add-hook 'LaTeX-mode-hook 'turn-on-reftex) (setq reftex-plug-into-AUCTeX t) (setq reftex-external-file-finders '(("tex" . "kpsewhich -format=.tex %f") ("bib" . "kpsewhich -format=.bib %f")))
to your .emacs configuration.
You can conveniently insert environments like itemize, list, etc. with C-c C-e and then typing what kind of environment you want.
dired
Open with C-x d.
Still working on it.
Image from www.sachachua.org
org-mode
Open with C-x org-mode. Still working on it.
Image from www.sachachua.org
Image from www.sachachua.org
Cheatsheet