Overview

HTTPS SSH
<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* - [Install](#install) - [Ubuntu requirements](#ubuntu-requirements) - [Texinfo](#texinfo) - [Latest git](#latest-git) - [Copy configuration file (optional)](#copy-configuration-file-optional) - [Org-mode problem with Babel](#org-mode-problem-with-babel) - [Running emacs for beginners](#running-emacs-for-beginners) - [Start from learning very standard non-customized emacs keys](#start-from-learning-very-standard-non-customized-emacs-keys) - [Situations which makes most novices lost](#situations-which-makes-most-novices-lost) - [Your cursor at the bottom of screen, no idea how to get it back](#your-cursor-at-the-bottom-of-screen-no-idea-how-to-get-it-back) - [My (avk) key bindings plus standard keybindings](#my-avk-key-bindings-plus-standard-keybindings) - [General editing keys:](#general-editing-keys) - [Working with blocks (regions)](#working-with-blocks-regions) - [Named regions](#named-regions) - [Function keys](#function-keys) - [Quick switching between open buffers](#quick-switching-between-open-buffers) - [helm specific keys](#helm-specific-keys) - [Misc keys](#misc-keys) - [Find/Replace](#findreplace) - [Windows & Frames](#windows-&-frames) - [Terms](#terms) - [Keys](#keys) - [Plan for beginners (advanced level in 1 month of intensive usage)](#plan-for-beginners-advanced-level-in-1-month-of-intensive-usage) - [Week 1 (use raw emacs in terminals and basic key bingings)](#week-1-use-raw-emacs-in-terminals-and-basic-key-bingings) - [Week 2 (configuration tweaks, useful modules)](#week-2-configuration-tweaks-useful-modules) - [Be able to configure settings to own taste. Learn how emacs configuration works.](#be-able-to-configure-settings-to-own-taste-learn-how-emacs-configuration-works) - [Professional switching between open files, project files, search results](#professional-switching-between-open-files-project-files-search-results) - [Week 3 (advanced core modules usage)](#week-3-advanced-core-modules-usage) - [Week 4 - learn specific modules](#week-4---learn-specific-modules) - [Magit](#magit) - [Org-mode](#org-mode) - [Your specific modes](#your-specific-modes) - [Learn how to alter your configuration, use lisp snippets](#learn-how-to-alter-your-configuration-use-lisp-snippets) <!-- END doctoc generated TOC please keep comment here to allow auto update --> Install ======= ``` example hg clone https://bitbucket.org/avkoval/.emacs.d ``` Ubuntu requirements ------------------- ### Texinfo Texinfo is needed for flycheck. ``` example sudo apt-get install texinfo ``` ### Latest git Magit package always require latest git version. You need to download it, for example following this [advice](https://askubuntu.com/questions/568591/how-do-i-install-the-latest-version-of-git-with-apt/568596): ``` example sudo apt-add-repository ppa:git-core/ppa sudo apt-get update sudo apt-get install git ``` Copy configuration file (optional) ---------------------------------- To tweak configuration settings you should copy .emacs.d/init.el into your home directory .emacs *(optional but recommended step)*: ``` example cp .emacs.d/init.el ~/.emacs ``` Org-mode problem with Babel --------------------------- If your system already had org-mode installed, then installation of latest org-mode will contain compilation error, which is apparently [very hard to debug](https://github.com/syl20bnr/spacemacs/issues/7641). The fix: ``` example rm .emacs.d/elpa/org-201*/*.elc ``` Running emacs for beginners =========================== Emacs strives for maximum power, and because of this it binds keys on very unusual key combinations. Beginners find it difficult to accomodate to different copy/paste behavior and some other things. But please be patient, if you overcome those problems, you will obtain more power in your hands. Start from learning very standard non-customized emacs keys ----------------------------------------------------------- Because you might need to run emacs without custom configuration on remote terminals and elsewhere you need to learn all standard keybindings first. Later, in your customized configuration you might want to override some for best productivity, but learning the core keys in the first stage is very important. To excel in this, you need to follow those two simple steps: - Learn emacs tutorial by pressing C-h t (Control+'h' and then 't'). - Print and use this reference card <https://www.gnu.org/software/emacs/refcards/pdf/refcard.pdf> A very short introduction to emacs keys: | Action | Key | |-------------------------------------|-------------| | Exit emacs | C-x C-c | | Open file | C-x C-f | | Save file back to disk | C-x C-s | | Start mark | C-SPC | | Copy mark | M-w | | Paste mark | C-y | | Close buffer (kill buffer) | C-x k | | Next buffer | C-x `RIGHT` | | Previos buffer | C-x `Left` | | Buffer list | C-x C-b | | Next window | C-x o | | Keep 1 window | C-x 1 | | Quit from some running emacs app | q | | Kill running emacs app | C-g | | About recursive edit (command line) | C-\] | | Undo | C-x u, C-\_ | | Dired (file browser) | C-x d | Where: - C = Control key - M = usually Alt key - S = Shift key Notes on Emacs specific terms: - File is named 'buffer' - Selection Block is named 'region' - Window and Frame might mean opposite things Situations which makes most novices lost ---------------------------------------- A new frame appears on screen, you have no idea how to exit it. Example: ![](file:assets/ss_20160926182739_5nFf6OwtNO5S2CJmG9dD.png) Answer: - You have opened some internal buffer. No need to worry, to return to single window view - press `C-x 1` - If you find yourself in wrong window, press `C-x o` first to move cursor to other window. Your cursor at the bottom of screen, no idea how to get it back --------------------------------------------------------------- Like this: ![](file:assets/ss_20160926183028_tcrviCiXcDOn34q4b9ON.png) - Press `C-g`. Should help. If does not: press `C-]` (several times). If cursor is not in the frame where your file is, use `C-o` until its returned. My (avk) key bindings plus standard keybindings =============================================== (but look also in [file:./configs/cfg\_keybindings.el](./configs/cfg_keybindings.el)) General editing keys: --------------------- | Action | Key | Notes | |------------------------------------|-------------------------|-----------------------------------------| | Duplicate current line | C-+ | 'kill-ring' safe | | Insert line above | C-S-insert | Control Shift Insert | | Delete current line | C-S-backspace | 'kill-ring' safe | | Delete current line (and yank) | C-a C-k | or select region and C-w | | Comment or uncomment selected | C-S-z | | | Match paren | M+\] | | | Scrolllock mode | C-Scroll<sub>Lock</sub> | | | Delete current buffer (close file) | C-x C-k, M-DEL | | | Text position (3 pos) | C-l | | | Delete whitespace | C-z d | | | Suspend frame (go background) | C-z C-z | Std. combination for this action is C-z | | | | but I need C-z for other things | Working with blocks (regions) ----------------------------- | Action | Key | Notes | |-------------------|------------|--------------------------| | Select region | C-SPC | Or use Shift+cursor keys | | Copy region | M-w, C+INS | Control-Insert | | Yank (cut) region | C-w | | | Insert region | C-y, S+INS | Shift-Insert | Named regions ------------- In emacs you can copy selected region to a named memory place. So, this makes it possible to operate with different selected pieces of text. | Action | Key | Notes | |-----------------------------------|---------------|--------------------| | copy to named memory register | C-x rs `CHAR` | Example: C-x r s 1 | | insert from named memory register | C-x ri `CHAR` | C-x r i 1 | Function keys ------------- | Action | Key | Notes | |-------------------------------------------------|------------|--------------------------------| | Manual | F1 | same as man `topic` in console | | Save | F2 | | | Open | F3 | | | Next window | F6 | | | Previous window | S-F6 | | | Query & replace in this buffer | F7 | | | Query & replace in files | Contrl+F7 | | | Next compilation error | F8 | | | Jump to bookmark | C-F8 | | | Ibuffer (open buffer=files list) and management | F9 | | | Menu | F10 | | | Toggle line numbers | F11, C-z l | | | Toggle display of long lines | F12 | | Quick switching between open buffers ------------------------------------ I strongly sugges to enable cfg<sub>helm</sub>.el in your custom copy of .emacs as its a primary additional module for switching between files and buffers. | Action | Key | Notes | |------------------------------------------------|---------|--------------------------------| | Switch buffers | C-x C-b | Shows the list of open buffers | | Switch buffers (helm enabled) via helm-recentf | C-z C-r | helm-recentf | | Switch buffers | C-z C-b | | | Switch buffers (Ibuffer) | F9 | | helm specific keys ------------------ Excellent helm module [Read more here](https://github.com/emacs-helm/helm) provides reach functionality of switching between buffers, files, searching, etc. Enable this by uncommending cfg<sub>helm</sub>.el Most important keys listed below: | Key | Command | What it does | |---------|----------------------------|------------------------------------------------| | C-c v | helm-imenu | Show document structure (functions, classes | | s-‹ | | for Python) | | C-c C-z | helm-recentf | Recentf is one of the most powerful emacs+helm | | C-z C-r | | keybindings. Shows recently open files | | s-x | | | | C-c h p | helm-projectile | Find file in project | | s-CPC | helm-mini | mini view with buffers, recentf combined | | C-f12 | | | | C-z C-a | | | | C-c h m | helm-mark-ring | Shows recent locations in this file | | Alt-F9 | | | | C-z o | helm-occur | Shows occurencies of smth. in the file | | C-c h a | helm-ag | A very fast search in files. First match like | | | | a grep, 2nd match in helm | | C-z f f | helm-etags-select | Etags search for project files. For python | | C-z f t | | project you need to create tags first, use | | | | create-TAGS emacs cmd | | C-z C-f | helm-find-files | Find files using Helm. Rich functional | | f3 | | via TAB. | | C-z f a | avk-change-default-font-fn | My function to change font | | C-c h b | helm-bookmarks | Bookmarks API to emacs bookmarks | | C-c h f | helm-firefox-bookmarks | Firefox bookmarks | | C-x c / | helm-find | Find files by name | | C-c h r | helm-resume | Resume last helm screen | Misc keys --------- | Action | Key | Notes | |-----------------------------|--------------------|-------| | Change font (helm required) | C-z fa | | | Change emacs skin (theme) | C-z tt | | | Lower region | C-x l | | | Upper region | C-x u | | | Dired (show files) | C-x d | | | Dired (by file mask) | C-x d `enter mask` | | | ZTree (show files by tree) | C-x z | | Find/Replace ------------ | Action | Key | Notes | |-----------------------------------|-----------|-------| | Find in current file | F7 | | | Find in current file (occur) | M-x occur | | | Find in current file (helm-occur) | C-z o | | | Search in files | C-F7 | | | Search for file name | C-S-D | | Windows & Frames ---------------- ### Terms - **Window** is some area within emacs screen with modeline. - **Frame** is another frame of the editor. One editor can span multiple frames. ### Keys | Action | Key | |--------------------------|----------------------| | Keep one window | C-x 1, C-ESC | | Add new frame | C-x 5 2 | | Add new window at bottom | C-x 2 | | Add new window at right | C-x 3 | | Close window | C-x 0 | | Close frame | C-x 5 0 | | switch between windows | C-x o, F6 | | switch between windows | WIN+Shift Arrow Keys | | next frame | C-x 5 o | Plan for beginners (advanced level in 1 month of intensive usage) ================================================================= Week 1 (use raw emacs in terminals and basic key bingings) ---------------------------------------------------------- OK. On first week my general recommendation it to learn some basic keys and work in terminal. So, print out the PDF cheatsheet from [2.1](#*Start from learning very standard non-customized emacs keys) chapter, run throught tutorial and try emacs in remote terminals. Week 2 (configuration tweaks, useful modules) --------------------------------------------- ### Be able to configure settings to own taste. Learn how emacs configuration works. On this week you can learn how to tweak some emacs settings for your preference. This includes reassigning some keys for your taste (look for example in [file:./configs/cfg\_keybindings.el](./configs/cfg_keybindings.el)), and use configuration dialogs: `M-x configure-variable` and `M-x configure-group`. ### Professional switching between open files, project files, search results On this week you also have to study and be able to perform generic actions like: - Switch between files in project using helm (C-c h p) - Use **dired**: - `C-x d` start it, `q` - quit - Use **ZTree** - `C-x z` - Switch between open files using ibuffer (F9) - Learn how to close buffers (`d`), and how to execute action (`x`) in generic Emacs dialogs - How to sort `s` ... - How to filter `/` ... - Quick find file by name. - Using **dired**: `C-S-d` - Using **helm**: `C-c x /` - Find text in files: - Using **rgrep** (`C-F7` and/or `M-x rgrep`) - Using **silver search** in project files: `C-c s` Week 3 (advanced core modules usage) ------------------------------------ - Use / customize snippets (**yasnippet**) for your working environment - Edit files via sudo:// and <ssh://> - Advanced **dired** usage: - Find files by content - Mark/action on group files - Edit file names `C-c C-q` - ... - Use emacs shells for development and debugging using **realgud** debugger *optional* - Learn how to use emacs package manager: `M-x package-list-packages` Week 4 - learn specific modules ------------------------------- In your work environment you might need or skip any of these, but generally I advice you to learn as its a very useful tools. ### Magit **Magit** is a bit of magic in emacs - it makes your daily work with 'git' so easy that you never come back using your console. It makes most of common operations quick and fast and group operations like squashing your commits or merging with conflicts became an easy task with Magic. In my configuration **Magit** called via: `C-z g` and next you should try `y` to switch between branches or `s` to stage then `c` commit. At all, first thing to do is to press `?` to see all actions. Magit really don't require a lot of documentation as most of features are self-explaining via context help. ### Org-mode Those who wish to maintain information structured and connected way org-mode provides it. The usage varies from preparing documentation, maintaining your tasks list to professional usage like maintaining results of some science experiments and evaluating external language blocks. ### Your specific modes For most of languages emacs have specific support which is called 'major mode'. For most common languages support is included into this configuration, but if you miss something, press `M-x package-list-packages` and look for your package. Language support packages called modes, like: **python-mode** or **yaml-mode** ### Learn how to alter your configuration, use lisp snippets Usually, your algorighm is this: - Google or try to find in emacs configuration (`M-x configure-*`) the settings you wish to change - Find *Lisp* example code, put into your configuration file (I usually suggest to split this to configs/cfg<sub>\*</sub>) try to execute with `C-x C-e`.