# Buffers and basics

C-g keyboard-quit ; press couple times to cancel most things emacs might be doing
C-x C-c kill-emacs ;exit emacs
C-x C-s save-buffer ;saves current file
C-x C-b list-buffers ;opens buffers window
C-x b switch-to-buffer ;if one knows the buffer by name
M-x execute-extended-command ; exec func by name

# Windows

C-x o other-window ;to switch to other window
C-x 1 delete-other-windows ;have one window (close others)
C-x 3 split-window-right ;vertical split
C-x 0 delete-window ;closes the current window

http://www.jesshamrick.com/2012/09/10/absolute-beginners-guide-to-emacs/

# Movement

C-n next-line
C-p previous-line
C-a move-begining-of-line
C-e move-end-of-line
C-v scroll-up-command
M-v scroll-down-command
M-f forward-word
M-b backward-word
C-f forward-char
C-b backward-char
C-M-f forward-sexp
C-M-b backward-sexp
M-< beginning-of-buffer ;also C-{home}
M-> end-of-buffer ;also C-{end}
M-g g goto-line
M-. xref-find-definitions ; jump to def
M-, xref-go-back ; jump back from the above
M-? xref-find-references

# Basic edit

C-SPC set-mark-command ;allows to select text by moving afterwards
M-w kill-ring-save ;pseudo copy command
C-y yank ; pseudo paste
C-w kill-region ; pseudo cut command

C-o ;insert line above this one
C-n C-o ;insert line below this one (really two commands but it does the trick)
C-a C-k C-k ;Kill line (dd)


# Help

C-h f describe-function
C-h k describe-key
C-h b describe-bindings
C-h v describe-variable
C-h m describe-mode

;shows the content of the kill-ring variable
C-h v kill-ring

# Others

;move block of code
C-c > shifts the region 4 spaces to the right
C-c < shifts the region 4 spaces to the left

;the above may not always work
move by 2 to right
C-u 2 C-x Tab

move by 8 to left
C-u -8 C-x Tab

; may add/leave tabs/spaces
tabify / untabify

;replace plain
M-% string RET newstring RET

;replace regexp
C-M-% regexp RET newstring RET

C-x h mark-whole-buffer ;select all text

;run shell command on the selected text
(shell-command-on-region) M-|

;if above prefixed with C-u it will replace the selected region

;Clojure/CIDER/Lisp things
C-c M-j  cider-jack-in-clj
C-x C-e  cider-eval-last-sexp
C-c C-k  cider-eval-buffer
C-c C-q  cider-quit

;recompile elisp
(byte-recompile-directory "~/.emacs.d/elpa" 0 t)

;reload buffer from disk
(revert-buffer)