Sunday 9 March 2014

Emacs Cheatsheet

Commands mentioned here works on GNU Emacs but does not cover every command. A subset of these commands may work on Zile, XEmacs and others.

Note: C stands for Ctrl and M stands for either Alt or Esc

Command                Description
----------------------------------------------------------------------------------------
C-x C-c          Quit completely
C-g                Quit a partial entered command
C-v                Move forward one screen
M-v                Move back one screen
C-l                 Move text on which cursor is to center of screen (Pressing again leads to movement, first to top, then to bottom and back)

C-p                Move to previous line
C-b                Move backwards character by character
C-f                 Move forwards character by character
C-n                Move to next line
M-f                Move forward word by word (when cursor is between word, then move cursor to end of word)
M-b               Move backwards word by word (when cursor is between word, then move cursor to beginning of word)
C-a                Move to beginning of line (if at beginning, then does nothing)
C-e                Move to end of line (if at end, then does nothing)
M-a               Move to beginning of sentence (if repeatedly pressed, cursor moves to previous sentence's beginning)
M-e               Move to end of sentence (if repeatedly pressed, cursor moves to next sentence's end)
M-<               Move to beginning of whole text
M->               Move to end of whole text
C-u Number Command        Repeat the command "Number" times (Works for most commands)
M-Number Command        Repeat the command "Number" times (Works for most commands)
C-u Number C-v            Scroll text forward by "Number" lines (not screenfull)
C-u Number M-v            Scroll text backward by "Number" lines (not screenfull)
C-x 1                Kill all windows except the current one
C-u Number Character        Insert "Character" "Number" times at current cursor position
C-d                Delete character at current cursor position 
Backspace    Delete character before current cursor position (If used with C-u, then will kill instead of delete)
M-Backspace Kill word before current cursor position
M-d                Kill word after current cursor position 
C-k                 Kill from current cursor position till end of line (if pressed repeatedly, will kill the newline) (If used with C-u Number will kill, instead of delete)
M-k                Kill from current cursor position till end of sentence
C-Space         Start highlighting from current cursor position
C-w                Kill all text previously highlighted by "C-Space"
C-u Number C-k            Kill the "Number" lines along with their newlines
C-y                Yank (Paste) latest killed text at current cursor position (If several C-k were used, then would yank all killed)

M-y                Yank second latest killed text (If pressed repeatedly, then would come back to latest kill) (Could be used with C-u)

C-/                Undo (If used with C-u, then repeat undo "Number" times)
C-_                Undo (If used with C-u, then repeat undo "Number" times)
C-x u             Undo (If used with C-u, then repeat undo "Number" times)
C-x C-f          Open file or create new file
C-x C-s          Save file
C-x C-b          Show the list of buffers
C-x b buffername        Goto "buffername" buffer
C-x s             Save buffers which had changes in them
C-x C-c         Quit emacs
C-z                Suspend Emacs
fg                 Resume Emacs
%emacs       Resume Emacs
M-x repl s string replace    Replace all occurrences of "string" with "replace" after the current cursor position
M-x recover-file        After opening file, if during editing system crashes, this command can be used to recover or get back changes

M-x mode-name            Change mode to "mode-name" (Use text-mode for editing text, use minor mode: auto-fill-mode for human language text)

C-h m                Shows help on current mode
C-u number C-x f        Change margin to "number" (default is 70)
M-q                Re-fill paragraph (if paragrah is made up of sentences, some at new lines, then pressing this would connect them at the period)

C-s string            Search for string in forward direcrion (Enter to terminate search, keep pressing it for next occurrence of "string", after this is Backspace is pressed the cursor would jump to previous occurence of string)

C-r string            Search for string in reverse direction (Enter to terminate search, keep pressing it for next occurrence of "string", after this is Backspace is pressed the cursor would jump to previous occurence of string)

Note:     If control characters are typed other than C-s and C-r, the search terminates

C-x Number            Split the screen into "Number" frames, each displaying the same file
C-x o(other)            Bring the cursor to the other frame
C-M-v                      Scroll other frame (cursor remains where it was)
Escape C-v              Scroll other frame (cursor remains where it was)
C-x 4 C-f                  Open a different file in new frame (Cursor also moves to new frame)
M-x make-frame     Create new window
M-x delete-frame    Delete selected window
Escape Escape Escape        Get out of recursive editing level or out of minibuffer
C-h ?                       Get help on everything
M-x help                  Same as C-h ?
F1                           Same as C-h ?
C-h c Command     Tells "Command" name (Here "Command" is of the form C-x, M-v, C-x C-s, etc...)
C-h k Command            Displays documentation of the "Command" (Here "Command" is of the form C-x, M-v, C-x C-s, etc...)

C-h f Command-name        Displays documentation of "Command-name" (Here "Command-name" is of the form previous-line, etc...)
C-h v variable-name        Displays documentation of "variable-name" (Here "variable-name" refers to all variables some of which can be used to customize Emacs)

C-h a               Search for commands
C-h i                Info (Use "m emacs" to read Emacs Manual, type ? for guided tour)
C-h r               Read Manual

Note:
Use Tab for auto-completion of commands.

If you want to download it, here you go.

As Always thanks for reading and please comment.

No comments:

Post a Comment

Stuff that most try to do