MYF

The Beginning of Emacs

Useful Resources:

Installation of the latest emacs on macOS

1
2
3
brew install emacs --with-cocoa
# restart terminal
emacs --version

Notes

To compile: C-c C-v

Run shell in emacs: M-x shell

close windows: C-x 0

comment: choose, M-x comment-region

uncomment: choose, M-x uncomment-region

undo: C-x u

Configuration

Steve Purcell

1
2
git clone https://github.com/purcell/emacs.d.git ~/.emacs.d
git clone https://github.com/emacs-evil/evil ~/.emacs.d/evil

Emacs Tutorial

Access to Tutorial:M-x help-with-tutorial

To end the Emacs session: C-x C-c

To quit a partially entered command: C-g

To scroll down: C-v. Note that there is an overlap of two lines when you scroll a whole screenful.

To scroll up: M-v

Clear screen and redisplay all the text, moving the text around the cursor to the center of the screen: C-l. By hitting the shortcut, it will move to the center of your screen, and then trigger C-l, it will move to the top of your screen, and then, move to the bottom of your screen.

Arrow:

  • Previous line: C-p
  • Next line: C-n
  • Backward a character: C-b
  • Forward a character: C-f
  • To move backward a word: M-b
  • To move forward a word: M-f
  • To move to the beginning of a sentence: M-a
  • To move to the end of a sentence: M-e
  • To move to the beginning of a line: C-a
  • To move to the end of a line: C-e
  • To move to the beginning of a buffer: M-<
  • To move to the end of the buffer: M->

Numeric argument: C-u 8 C-n is the same as run 8 times C-n, so does it work with other movement.

  • scroll the text up by 8 lines: C-u 8 C-v
  • scroll the text down by 8 lines: C-u 8 M-v

Windows Management:

C-x 1: one window(kill all other windows)

There is a whole series of commands that start with CONTROL-x; many of them have to do with windows, files, buffers, and related things. These commands are two, three or four characters long.

Here is a summary of the delete operations:

command effect
<DEL> Delete the character just before the cursor
C-d Delete the next character after the cursor
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

Set mark: C-<SPC>

Kill the textC-w

The difference between “killing” and “deleting” is that “killed” text can be reinserted (at any position), whereas “deleted” things cannot be reinserted in this way (you can, however, undo a deletion–see below).

Note that a single C-k kills the contents of the line, and a second C-k kills the line itself, and makes all the other lines move up. C-k
treats a numeric argument specially: it kills that many lines AND their contents. This is not mere repetition. C-u 2 C-k kills two
lines and their Newlines; typing C-k twice would not do that.

After you have done C-y to get the most recent kill, typing M-y replaces that yanked text with the previous kill. Typing M-y again and again brings in earlier and earlier kills.

Undo

Undo the change with command C-/. C-_ is an alternative undo command.

A numeric argument to C-/, C-_ acts as a repeat count.

Files

  • C-x C-f: Find a file and open
  • C-x C-s: Save the file

Buffers

  • C-x C-b List Buffers
  • C-x b switch to some buffer
  • C-x C-s Save current buffer
  • C-x s Save some buffers

Extending the Command Set

When you type M-x, Emacs prompts you at the bottom of the screen with M-x and you should type the name of the command; in this case, “replace-string”. Just type repl s<TAB> and Emacs will complete the name.

M-x replace-string: changed the word whenever it occurs after the initial position of the cursor.

Auto Save

When you have made changes in a file, but you have not saved them yet, they could be lost if your computer crashes. To protect you from this, Emacs periodically writes an “auto save” file for each file that you are editing. The auto save file name has a # at the beginning and the end; for example, if your file is named “hello.c”, its auto save file’s name is “#hello.c#”. When you save the file in the normal way, Emacs deletes its auto save file.

If the computer crashes, you can recover your auto-saved editing by finding the file normally (the file you were editing, not the auto save file) and then typing M-x recover-this-file <Return>. When it asks fo confirmation, type yes to go ahead and recover the auto-save data.

Searching

  • C-s: forward search
  • C-r: reverse search

Multiple Windows

  • C-M-v scroll the next window
  • C-x o switch window
  • C-x 4 C-f filename Specified file appear in the next window and cursor goes there too.

Multiple Frames

A frame is what we call one collection of windows, together with its menus, scroll bars, echo area, etc. On graphical displays, what Emacs calls a “frame” is what most other applications call a “window”. Multiple graphical frames can be shown on the screen at the same time. On a text terminal, only one frame can be shown at a time.

  • C-x 5 2: See a new frame appear on your screen
  • C-x 5 0: Removing the selected frame.

Recursive Editing Levels

You cannot use C-g to get out of a recursive editing level. This is because C-g is used for canceling commands and arguments WITHIN the
recursive editing level.

Getting More Help

To use the Help features, type the C-h character, and then a character saying what kind of help you want.

To find the brief description of the command(e.g. C-p): C-h c C-p. For more information, use C-h k C-p

More Features

C-h r

GNU General Public License.