Emacs Commands


Useful Commands

List of useful Emacs Commands


Key Abbreviation

C-x denotes pressing the 'Ctrl' key and 'x' key together.

M-x denotes pressing the 'Alt' key and 'x' key together.

C-x h denotes pressing the 'Ctrl' key and 'x' key together, then pressing the 'h' key on its own.



Starting & Stopping

Emacs - start emacs
C-x C-c - exit emacs (Why would you do that?)

Movement Actions

C-f - forward one character
C-b - back one character

C-n - next line
C-p - previous line

C-a - start of line
C-e - end of line

M-f - forward a word
M-b - backward a word

M-a - start of sentence
M-e - end of sentence

M-} - start of paragraph
M-{ - end of paragraph

M-< - start of buffer
M-> - end of buffer

C-v - down one screen/page
M-v - up one screen/page

C-l - clear screen

File/Buffer Actions

C-x C-f - open file
C-x s - save buffer

C-x C-s - save file
C-x C-w - save as file (save to new name)

C-x C-c - exit Emacs (You never need this!)
C-z - suspend Emacs
C-g - abort current action

C-x C-f - open another file in the session

C-x C-v - open alternative file
C-x i - insert file into current buffer


C-x b [Return] - opens default buffer
C-x b [OldFile] - opens buffer [OldFile]

C-x b [NewFile] - creates new buffer [NewFile]
C-x C-b - opens buffer list

C-x z - repeat command 1 x time
C-x z z - repeat command 2 x times
C-x z z z z - repeat command 4 x times
Each additional "z" repeats the command once more

Delete/Edit Actions

Backspc - delete character left

C-d - delete character right
C-h - delete character left (I modified emacs)

M-d - delete word right
M-backspc - delete word left (I dont use this. see below)

C-k - delete to end of line (hold deleted in kill-buffer)
M-k - delete to end of sentence

C-y - paste last deleted text item
(retrieve kill-buffer content)
M-y - paste next deleted text item
(cycles thru kill ring buffer)

C-w - cut the currently selected text, and copy
M-w - copy highlighted text without cutting

C-x h - highlight whole file
C-space - begin highlight text

C-o - insert new line
C-x C-o - delete consecutive blank lines

Search/Replace Actions

C-s - forward incremental search
C-r - backward incremental search
C-s [Return] C-w - forward word search

M-% - query replace (interactive)
M-% spc (or y) - replace and show next instance
M-% del (or n) - skip and show next instance
M-% . - replace this instance and quit
M-% , - replace and pause (spc or y to continue)
M-% ! - replace all don't ask
M-% ^ - back to previous instance
M-% [Return] - exit query-replace (q also quits)

C-n [command] - repeat command n times
M-n [command] - repeat command n times

C-u [command] - repeat command 4 times
C-u C-u [command] - repeat command 16 times


Paragraph/Region Actions
C-@ - mark start or end of region
C-spc - mark start or end of region

C-y - paste region or deleted text
M-y - paste earlier deletion

C-t - transpose chars
M-t - transpose words
C-x C-t - transpose lines

M-c - capitalize word
M-u - upcase word
M-l - downcase word

NOTE
Ctrl-w normally cuts current selected text but I modified it to kill-to-start-of-line. Its the opposite of Ctrl-k, kill-to-end-of-line. Now if I'm editing in the middle of text and its wrong I can kill-to-start-of-line and re-do. Or I can kill-to-end-of-line and re-do.

Another change I implemented was to remap Ctrl-h. This no longer calls help but deletes the character to the left. Similar to the command line edits in bash shell.

Undo

C-x u - Undo
C-x / - Undo

Window Control

C-x o - jump to other buffer (thats 'o' not zero)
C-x 1 - close other buffers

C-x 2 - split buffer horizontally
C-x 3 - split buffer vertically

C-x C-b - display all buffers
C-x b - move to another buffer


Help

C-h ? - get more info on help
C-c ? - like apropos (prompted for text. All symbols with text displayed in a buffer).

Various

C-h b - display the keybindings in effect (C-h brings up help)
C-c C-p - display earlier command (repeated C-c C-p cycle through earlier commands)

C-c C-r - prompted in minibuffer for text. (most recent command with text displayed)
C-c a - display argument list in minibuffer (prompted for function name. Defaults to nearest symbol).

Shell Actions
M-x shell - start shell session
M-x eshell - start emacs shell session
M-! - execute shell command


Spell Check Actions
M-$ - spell check word

Recursive Editing Levels

M-x top-level [Return] - exit recursive editing
; If you get stuck in recursive editing levels, do above

M-x set-buffer-file-coding-system unix - change DOS file to Unix
; Will convert file unix from dos or windows format
; Note: You need to save the file.
; Ctrl-s - to save file in new unix format

M-% replace-string Ctrl-q Ctrl-m [Return] [Return]
; Delete ^M end-of-line chars

M-x - describe key
; Example Alt-x 'describe-key' M->
; M-> runs the command end-of-buffer