Emacs documentation

Table of Contents

1 Links/Resources

2 General

2.1 When exiting but many files are open and unsaved.

When you are working with only a single file, you can see the file on your screen when Emacs asks if you want to save it. However, when you are editing more than one file, Emacs will ask you about each file in turn, and you may have forgotten what was in one of the files. If so, when Emacs asks what to do with that particular file, press C-r . Emacs will show you the file, so you can make an informed decision. As you are looking at the file, you will be in VIEW MODE, which means you can read the file, but not make any changes. To quit viewing the file, press q (for quit). Finally, if you forget what any of the choices mean, press C-h to display a quick help summary. To get rid of the help information, press q . To summarize, you stop Emacs by pressing C-x C-c .

key description
y Save the specific file
n Do not save the specific file
! Save all the remaining files
q Quit immediately without saving
. Save the specific file and then quit
C-r View the specific file
C-h Display help info

Emacs will start by creating one large window containing a buffer named scratch . There will be a few lines at the top with some useful information. To erase these lines, use C-x h C-w . ( C-x h selects the entire buffer; C-w erases the selection.)

3 Keyboard shortcuts

3.1 General

Keys Cmd name Description
M-<   Beginning of buffer
M->   End of buffer
C-SPC C-SPC   Set the mark, pushing it onto the mark ring
C-u C-SPC   Go back in points mark ring.
C-x b <NAME> RET   Create new named buffer
C-x h   Mark everything in buffer
M-!   Shell command
M-x recover-file   Recover file if “cache” is saved
M-3 C-n   3 lines down
C-u 3 C-n   3 lines down
M-u   Uppercase
M-l   Lowercase
M-c   Capitalize
M-$   Spellcheck
  ispell-region Spellcheck region
  ispell-buffer Spellcheck buffer
M-q   Fix Fill-mode
M-/ dabbrev-expand Autocomplete

3.2 Help

Keys Description
C-h ? Help about help
C-h C-h Help for help
C-h t Tutorial
C-h i Info
C-h f <function name> Info about a function, reading the docstring
C-h v <variable> Variable info
C-h p Search the standard Emacs Lisp libraries
C-h m Help in that mode
C-h k What does the keys do
C-h a Seach command

4 Org-mode

4.1 Options

Command Description Alternatives
#+TITLE: Document title  
#+DATE: Date  
#+AUTHOR: Author  
#+MAIL: Mail address  
#+LaTeXCLASS: Latex document type article, book
#+OPTIONS: Document options toc:nil
#+STARTUP: overview
#+STARTUP: content
#+STARTUP: showall
#+STARTUP: showeverything

4.2 Keys

Keys Description Extra useful Command
<Tab> Open / Close item    
S-<Tab> Toggle open items, global    
M-<Enter> Create new item of same type    
M-<Up> Reorder item up    
M-<Down> Reorder item down    
M-<Right> Indent item    
M-<Left> Reindent item    
C-c C-w Move headline to another top level    
C-c C-n Next heading    
C-c C-p Previous heading    
C-c C-f Next heading same level.    
C-c C-b Previous heading same level.    
C-c C-u Backward to higher level heading.    
C-c C-c Realign the columns without moving or creating new ones    
C-c C-e Export    
C-c C-l Insert link X  
C-c l Store place for link X  
C-c C-o Follow link (open link in browser) X  
<s - <TAB> Create source code block    
C-c ' Open code block and edit it in that mode    
C-c c org-capture    
C-c a org-agenda X  
C-c b org-iswitchb X  
C-c l org-store-link X  
C-c C-c Does alot of things, Run code in the block X  
C-c C-t Cycle TODO states    
C-c C-x C-a Move TODO to archive X org-archive-subtree-default
C-x n s Narrow one item X org-narrow-to-subtree
C-c n w Exit narrow X widen
C-c C-x p Set property X org-set-property

4.3 Todos

Keys Description
C-c C-t Get a menu of TODO keywords
<Shift> - <Right> Change status on TODO
<Shift> - <Left> Change status on TODO
C-c C-x C-s Mark as done and move to archive

5 Dired

Key Description
d Mark for deletion
u Undo mark
x Execute
r Rename
c Copy to
+ Create dir
g Update dir
C-x C-f Create file

6 Python

key command description
C-c C-z python-shell-switch-to-shell Start Python REPL in Emacs
C-c C-p    
C-c C-c   Send buffer to REPL

7 Shell

Key Description
M-x shell Open shell


IRC in Emacs

9 Literate DevOps

Babel commands Description
:ex ports code Exports only code
:exports both Exports both code and results
:dir <This dir> Have a dir as a var
:tangle <Path> Write the codeblock to a file
:results table The cmd output will be in a table
:results drawer The cmd output will be drawn
:results output The cmd output
:dir /sudo:: Access the dir as sudo
:session client Create a session

9.1 Local

This is on this local machine.

Do a simple list on the dir that is set to .. Save the results as a variable output.


Now we are taking [0,0] the first item in the list and do a cat on it to show its content. The reason we use [0,0] is because its a table and it can contain many cells.

du -h $AFILE

9.2 Remote

Here we will use tramp to execute on a remote server. We set the server in properties. The dir value is /kod3:, this is something that i have specified within my ~/.ssh/config file.

hostname --long

9.2.1 Log files

  • /var/log/nginx/error.log
  • /webapps/kodkollektivet.se/logs/django.log

Much of this needs to be running with root permissions, how to fix that?

Server setup docs this is a link to the this_server.md that is on the remote system. My home folder on kod3 this is a link to dired mode. Nginx error file as root .

zcat /var/log/nginx/error.log*.gz

10 Helm

Key Description
C-x r b helm-bookmarks

Author: John Herrlin

Created: 2017-02-23 Thu 17:59

Emacs 25.1.1 (Org mode 8.2.10)