Emacs Cheat Sheat

Table of Contents

Fork me on GitHub

1 Emacs

real_programmers.png

  • C- means hold down the Control key - Ctrl on a keyboard
  • M- means hold down the Meta key - often Alt or Esc on a keyboard
  • C-g can be used to quit a command you accidently started

File handling

  • Open or create (if it doesn't exits) a file
    • File (once opened) are loaded into a buffer, so we'll talk about buffers from here on in.
C-x C-f
  • Kill a buffer
C-x k
  • Switch to another open buffer
C-x b
#Note this gives you the option of entering any open buffer.
#Hitting return will open the last previous buffer you had open
#Alternatively you can type the name of a buffer (Tab for autocompletion remember)
  • Quit emacs
C-x C-x

Navigation

You can use the cursor keys to navigate forwards, backwards, up and down if you like. Emacs geeks will frown upon it and shout at you about the home-row, but it's up to you really.

  • Move forward and backward one character
C-f
C-b
  • Move to the next or previous line
C-n
C-p
  • Move to the beginning and end of a line
C-a
C-e
  • Move forward and backwards one word
M-f
M-b
  • Move up and down the page
C-v
M-v
  • Go to a specific line
M-g g
## Only useful if you can see line numbers though
M-x linum-mode
  • Go to beginning and end of buffer
M-<
M->
  • Go to a specific word
#For a word after your cursor
C-s 
#For a word before your cursor
C-r

Kill and Yank

  • Set a mark for beginning of selection
C-spc
  • Kill a line
C-k
  • Kill a selected region and place in kill ring
C-w
  • Copy a selected region into kill ring
M-w
  • Yank from the kill ring
C-y

UI Stuff

  • Split window vertically
C-x 3
  • Split window horizontally
C-x 2
  • Delete current window
C-x 0
  • Make current window the only window
C-x 1
  • Switch between windows
C-x o

Python Stuff

  • Setup to use Python3 over Python2
    • You need to edit (or create) a .emacs file in your home directory
    • Add this line
    (setq python-shell-interpreter "python3")
    
    • When you restart emacs you'll be using Python3
  • Open an interpreter in another window
C-c C-p
  • Execute the current Python Script
C-c C-c