You can quit Emacs with the following keybinding:
C-x C-c
Where C
is the control
key.
You can suspend Emacs using the following keybinding :
C-z
It gets you back to your shell. If you want to resume your emacs session, enter fg
in your terminal.
Re-Save open file under the same filename (Save):
C-x C-s
Write as filename
(Save As):
C-x C-w filename
The new file name will be prompted in the minibuffer.
Create new file or load existing file (New / Load):
C-x C-f filename
With the mnemonic here for f meaning file. You will be prompted for a file path in the minibuffer.
Visit alternate file
C-x C-f
If the file does not exist yet, you will be prompted the path of the file to create in the minibuffer.
Often you will get into a state where you have a partially typed command sequence in progress, but you want to abort it. You can abort it with either of the following keybindings:
C-g
EscEscEsc
"Window" in Emacs refers to what might otherwise be called a "pane" or "screen division". Some window manipulation commands include:
A "frame" in Emacs is what might otherwise be called a "window". Frames are manipulated using these commands:
Switching windows can be acheived using
Example of a buffer list
CRM Buffer Size Mode Filename[/Process]
. * .emacs 3294 Emacs-Lisp ~/.emacs
% *Help* 101 Help
search.c 86055 C ~/cvs/emacs/src/search.c
% src 20959 Dired by name ~/cvs/emacs/src/
* *mail* 42 Mail
% HELLO 1607 Fundamental ~/cvs/emacs/etc/HELLO
% NEWS 481184 Outline ~/cvs/emacs/etc/NEWS
*scratch* 191 Lisp Interaction
* *
Messages* 1554 Messages
The first field of a line indicates:
Select buffer. You can select out of any open buffer with the following keybinding:
C-x b
You will be prompted for the buffer name you wish to switch to.
List buffers:
C-x C-b
Save-some-buffer, giving the choice which buffer to save or not:
C-x s
Kill one buffer:
C-x k
Operations on marked buffers:
S Save the marked buffers
A View the marked buffers in this frame.
H View the marked buffers in another frame.
V Revert the marked buffers.
T Toggle read-only state of marked buffers.
D Kill the marked buffers.
M-s a C-s Do incremental search in the marked buffers.
M-s a C-M-s Isearch for regexp in the marked buffers.
U Replace by regexp in each of the marked buffers.
Q Query replace in each of the marked buffers.
I As above, with a regular expression.
P Print the marked buffers.
O List lines in all marked buffers which match a given regexp (like the function `occur').
X Pipe the contents of the marked buffers to a shell command.
N Replace the contents of the marked buffers with the output of a shell command.
! Run a shell command with the buffer's file as an argument.
E Evaluate a form in each of the marked buffers. This is a very flexible command. For example, if you want to make all of the marked buffers read only, try using (read-only-mode 1) as the input form.
W - As above, but view each buffer while the form is evaluated.
k - Remove the marked lines from the Ibuffer buffer, but don't kill the associated buffer.
x - Kill all buffers marked for deletion.
Save-some-buffer, giving the choice which buffer to save or not:
C-x s
Switch to the next buffer:
C-x RIGHT
Switch to previous buffer:
C-x LEFT
In Emacs, basic search tool (I-Search
) allows you to search after or before the location of your cursor.
To search for sometext after the location of your cursor (search-forward
) hit C-s sometext
. If you want to go to the next occurence of sometext
, just press C-s again (and so on for the next occurences). When cursor lands in the right location, press Enter to exit the search prompt.
To search before the location of your cursor (search-backward
), use C-r the same way you used before.
To switch from search-backward
to search-forward
, press 2 times C-s. And press 2 times C-r to search backward
when you're in search-forward
prompt.
Search and replace:
M-% (or Esc-% ) oldtext
Enter newtext
Enter
Set mark in cursor location:
C-space or C-@
Kill region (Cut):
C-w
Copy region to kill ring:
M-w or Esc-w
Yank (Paste) most recently killed:
C-y
Yank (Paste) next last killed:
M-y or Esc-y
kill
is the command used by Emacs for the deletion of text. The kill
command is analogous to the cut
command in Windows. Various commands exist that 'kills' one word (M-d), the rest of the line (C-k), or larger text blocks. The deleted text is added to the kill-ring
, from which it can later be yanked
.
Killing and yanking
Similar to the select-and-cut
feature in Windows, here we have C-spc. The key binding C-spc will start the selection, the user can move the mark with the help of arrow keys or other command to make a selection. Once selection is complete - push the C-w to kill the selected text
Some basic commands which can be used as quick reference for kill
command (taken from Emacs tutorial)
M-DEL Kill the word immediately before the cursor M-d Kill the next word after the cursor C-k Kill from the cursor position to end of line M-k Kill to the end of the current sentence
yank
describes the insertion of previously deleted text, e.g. using C-y which yanks the most recently killed text. Yank
command is analogous to the paste
command in Windows.
We know that the kill
command adds the text killed to a kill-ring
. To retrieve the deleted text from the kill-ring
use M-y command repeatedly until the desired text is yanked.
(Note: For the M-y key to work the previous command should be a YANK
otherwise it wouldn't work)
In addition to cursor movements using the arrow keys, Home, End, Page up, and Page down, emacs defines a number of keystrokes that can move the cursor over smaller or larger pieces of text:
By character:
By word
By line:
Entire buffer:
By 'block', depending on context (mode):
Typical key bindings:
Prefix arguments
In order to move several 'steps' at once, the movement commands may be given a prefix argument by pressing ESC or C-u and a number before the listed keystrokes. For C-u, the number is optional and defaults to 4.
E.g. ESC 3 C-n moves 3 lines down, while C-u M-f moves 4 words forward.
To undo something you just did:
C-_ or C-x u or C-/
Capitalize word: M-c
Convert word to upper case: M-u
Convert word to lower case: M-l
Emacs' documentation uses a consistent notation for all key bindings, which is explained here:
A "key chord" is obtained by pressing two or more keys simultaneously. Key chords are denoted by separating all keys by dashes (-
). They usually involve modifier keys, which are put up front:
Other keys are simply denoted by their name, like:
a
key;Examples of key chords thus include:
"Key sequences" are sequences of keys (or key chords), which must be typed one after the other. They are denoted by separating all key (or chord) notations by a space.
Examples include:
Key chords using the Alt modifier can also be entered as a key sequence starting with ESC. This can be useful when using Emacs over a remote connection that does not transmit Alt key chords, or when these key combinations are captured e.g by a window manager.
Example:
M-x can be entered as ESC x.
The same notation that is described here can be used when defining key bindings in Emacs lisp files.
Example:
(global-set-key (kbd "C-x C-b") 'buffer-menu)
binds the key sequence C-x C-b to the command buffer-menu