Short explanation of Emacs

[ambient page updated 11 Oct 05] ... [ home ] ... [ garrett@math.umn.edu ]

"C-x" means "Control-x", for example
"M-x" means "Meta-x" or "escape-x", for example

"point" means "cursor"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;       Starting, stopping
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

emacs &               ;; start emacs, in background
emacs  &    ;; start emacs on , in background

emacs -q ...          ;; start emacs without reading your .emacs file
                      ;; This may be helpful if you've screwed things up
                      ;; by being a little too creative!

C-x C-f       ;; find file (prompted for filename)
C-x C-s       ;; save file
C-x s         ;; save all files

C-x C-c       ;; save files, exit emacs

C-g           ;; stop/abort current command/process
				  ;;
				  ;; In a _search_, you'll have to do C-g C-g to stop

C-x u         ;; undo last command(s)
C-/           ;; undo last command(s)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;                Moving             ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

C-x k         ;; kill current buffer
C-x b         ;; move to another buffer (prompt for buffer name)

C-f           ;; move forward by one character
C-b           ;; move backward by one character
M-f           ;; move forward by one word
M-b           ;; move backward by one word

C-p           ;; move to previous line
C-n           ;; move to next line

C-v           ;; forward one screen
M-v           ;; backward one screen

C-a           ;; move to beginning of line
C-e           ;; move to end of line

C->			  ;; move to end of file
C-<			  ;; move to beginning of file

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;  Cutting and pasting              ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

C-d   ;; delete next character
M-d   ;; delete next word

DEL           ;; delete previous character
M-DEL         ;; delete previous word

C-k           ;; delete from point to end of line

C-SPACE       ;; set the mark (to delimit a region)
C-w           ;; cut region (between mark and point)
M-w           ;; copy region

C-y           ;; paste (last cut text)'
M-y           ;; after "C-y", paste

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;      Searching and Replacing      ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

C-s           ;; search forward for prompted-for string
C-r           ;; search backward for prompted-for string

C-s C-s       ;; repeat last search (without re-entering string)

RETURN        ;; exit search

M-%           ;; query replace 
              ;; (prompt for search-string and replace-string)

;; You can interrupt a query replace to do other editing by C-r, which enters 
;; a "recursive edit". The minibuffer mode will be put into brackets [...] 
;; while you're recursive-editing. To exit the recursive edit and return to
;; your query replace procedure, do C-].
;;
;; Recursive edits may be nested, hence the name.

SPACE or "y"  ;;(after M-%) _do_ replace this instance
"n"           ;;(after M-%) do _not_ replace this instance
!             ;;(after M-%) replace all without asking further


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;      More editing                 ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

C-t           ;; tranpose this and previous character
M-t           ;; tranpose this and previous word

M-c           ;; capitalize word
M-u           ;; uppercase word
M-l           ;; lowercase word

M-x goto-line        ;; go to line number (prompt for line number)
M-x ispell-buffer    ;; run spell-check on buffer
M-x untabify         ;; converts tabs to spaces between point and mark

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;  Help/Informational commands
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

C-h b	        ;; describe key bindings of current mode

C-h k (prompt for key)  ;; "describe-key": tell what this key does

M-x apropos    ;; give a regular expression at the prompt
                               ;; to search emacs' help for related things

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;  Evaluating Emacs Lisp expressions, functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; To run an _interactive_ function, do

M-x       ;; (and respond to the prompt, if any)

;; To evaluate an expression, do

M-:  

;; For example, M-: (setq x "hello")  
;; gives the variable x the value "hello" (a string)

C-x Esc Esc    ;; repeat last complex command: goes back in command history

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;  Miscellaneous helpful commands
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

M-x validate-tex-buffer   ;; in TeX mode checks matches of braces,
                          ;; etc.

M-x rmail-edit-current-message  ;; from rmail mode enters rmail edit mode
C-c C-c                         ;; return to rmail mode

M-x rmail-decode-quoted-printable  ;; in rmail-edit mode, cleans up some
                                   ;; benighted presentations/encodings

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;  Shell mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; to enter shell-mode, do

M-x shell 

;; the advantage of this is that all inputs, outputs, etc
;; are extremely editable from within emacs. All command line loops,
;; such as Python's, are thereby editable
;;
;; In general, the usual bash commands require prefixing by C-x
;;

M-p    ;; previous command (move back in command history)
M-n    ;; next command (in command history)

C-c C-o    ;; deletes output of previous command
C-c C-r    ;; moves back to previous command in window

(setq comint-input-ring-size 2000)  ;; sets command history to length 2000

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;   Bookmarks
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; bookmark-jump goes to the location of the "bookmark" in whatever
;; file you put it by bookmark-set

C-x r m                ;;   bookmark-set
C-x r b                ;;   bookmark-jump   ;; does TAB completion...

M-x bookmark-rename
M-x bookmark-delete
C-x r l                ;;   go to Bookmarks Menu

;;
;; In Bookmarks Menu mode

d     ;; mark for deletion
u     ;; unmark
r     ;; rename
x     ;; delete
s     ;; save all bookmarks
m     ;; mark
v     ;; view bookmarked spots ;; "f" also works on a single file
t     ;; toggle display longlist/shortlist
w     ;; location of file associated with bookmark
DEL   ;; remove mark from previous line
q     ;; exit bookmark list

;; also...

bookmark-insert  ;; inserts text of b'marked file at cursor
bookmark-write   ;; prompts for filename in which to save bookmarks
bookmark-load    ;; to load non-default files containing bookmarks

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


Unless explicitly noted otherwise, everything here, work by Paul Garrett, is licensed under a Creative Commons Attribution 3.0 Unported License. ... [ garrett@math.umn.edu ]

The University of Minnesota explicitly requires that I state that "The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota."