Emacs Commands Cheat Sheet

Posted : admin On 1/29/2022

Shell, Emacs, & Python (oh my!) Cheat Sheet Lawrence David 09.07.06 1 Shell To run these commands, only type in the part after the dollar sign. Replace both arguments and square brackets (don’t leave square brackets in). $ cp oldfile newfile $ mv oldfile newfile $ rm oldfile $ mkdir newdir $ rm -r olddir $ cd destination. Emacs has some great commands that offer aid in recovering or restoring the contents of a file. To abort commands that are either running or have been partially typed, click Ctrl + g. To recover a file whose data might have been lost, use the keys Alt + x to open the mini-buffer and then enter recover-file. Emacs Commands List C = Control M = Meta = Alt Esc Basics C-x C-f 'find' file i.e. Open/create a file in buffer C-x C-s save the file C-x C-w write the text to an alternate name C-x C-v find alternate file C-x i insert file at cursor position C-x b create/switch buffers C-x C-b show buffer list C-x k kill buffer C-z suspend emacs. Emacs-cheat-sheet.md Rule of thumb: when in doubt, C-g it out.

Emacs-cheat-sheet.md In penance for cracking stupid jokes on Twitter, here's my Emacs cheat sheet. Emacs has a steep learning curve, so I've tried to order them by importance so you could learn them in stages.

Emacs Commands Cheat Sheet

Motion

C-a

beginning-of-line

C-e

end-of-line

C-f

forward-char

C-b

backward-char

M-f

forward-word

M-b

backward-word

Editing

C-d

delete-char

Rubout

backward-delete-char

C-q

C-v

quoted-insert

M-TAB

M-C-i

tab-insert

C-t

Exchange the char before cursor with the character at cursor

M-t

Exchange the word before cursor with the word at cursor

M-u

Uppercase the current word

M-l

Lowercase the current word

M-c

Capitalize the current word

Killing and Yanking

Emacs Commands Cheat Sheet Cheat

C-k

kill-line

C-x Rubout

backward-kill-line

C-u

Kill backward from point to the beginning of the line

M-d

Kill from point to the end of the current word

M-Rubout

Kill the word behind point

C-w

Kill the word behind point, using white space as a word boundary

M-

Delete all spaces and tabs around point

C-y

Yank the top of the kill ring into the buffer at point

M-y

Rotate the kill ring, and yank the new top

Keyboard Macros

Emacs commands cheat sheet cheat

C-x (

Begin saving the chars typed into the current keyboard macro

C-x )

End saving the chars typed into the current keyboard macro

C-x e

Re-execute the last keyboard macro defined

Completing

TAB

Attempt to perform completion on the text before point

M-?

List the possible completions of the text before point

M-*

Insert all completions of the text before point generated by possible-completions

Manipulating the History

Return

accept-line

C-p

previous-history

C-n

next-history

M-<

beginning-of-history

M->

end-of-history

C-r

Search backward starting at the current line (incremental)

C-s

Search forward starting at the current line (incremental)

M-p

Search backward using non-incremental search

M-n

Search forward using non-incremental search

M-C-y

Insert the n-th argument to the previous command at point

M-

M-_

Insert the last argument to the previous command

Emacs Commands Cheat Sheet

Rectangles

C-x r k

Kill the text of the region-rectangle, saving its contents as the 'last killed rectangle'

C-x r M-w

Save the text of the region-rectangle as the 'last killed rectangle'

C-x r d

Delete the text of the region-rectangle

C-x r y

Yank the last killed rectangle with its upper left corner at point

C-x r o

Insert blank space to fill the space of the region-rectangle. This pushes the previous contents of the region-rectangle to the right

C-x r N

Insert line numbers along the left edge of the region-rectangle. This pushes the previous contents of the region-rectangle to the right

C-x r c

Clear the region-rectangle by replacing all of its contents with spaces

M-x

Delete whitespace in each of the lines on the specified rectangle, starting from the left edge column of the rectangle

C-x r t

Replace rectangle contents with string on each line

M-x

Insert string on each line of the rectangle

C-x <space>

Toggle Rectangle Mark mode. When this mode is active, the region-rectangle is highlighted and can be shrunk/grown, and the standard kill and yank commands operate on it

Miscellaneous

Emacs Cheat Sheet Gnu

C-x

C-r

re-read-init-file

C-g

Abort the current editing command and ring the terminals bell

M-a

M-b

If the metafield char x is lowercase run the command that is bound to uppercase char

ESC

Metafy the next character typed. For example, ESC-p is equivalent to Meta-p

C-_

C-x

C-u

Incremental undo, separately remembered for each line

M-r

Undo all changes made to this line

M-&

Perform tilde expansion on the current word

[email protected]

M-<space>

Set the mark to the point

C-x C-x

Swap the point with the mark

C-]

Move to the next occurance of current character under cursor

M-C-]

Move to the previous occurrence of current character under cursor

M-#

Without argument line is commented, with argument uncommented (if it was commented)

C-e

When in vi mode, switch to emacs mode

M-C-j

When in emacs mode, switch to vi mode

M-0, M-1, ...

Specify the digit to the argument

Notes

Cheat
  • Based on the cheat sheet from cheat-sheets.org.
  • Converted by @erggo.