Skip to content

Linux Foundations / Find your way around Linux ยท Step 59 of 63

Lesson: Emacs Exiting and HelpSwitch
โ† Linux Foundations

Shell and files

Emacs Exiting and Help

Leave Emacs safely and use its built-in help to answer your own questions.

Knowing how to get out, and how to ask for help, makes Emacs much less intimidating. C- means Ctrl and M- means Alt (Meta).

Exiting

Press C-x C-c. If a file buffer has unsaved changes, Emacs asks whether to save it. Answer y to save or n to leave it unsaved.

If you answer n, Emacs warns you and asks for confirmation:

text
Modified buffers exist; exit anyway? (yes or no)

Here you type the full word yes or no. The exact prompts can vary a little between versions and settings.

Suspending is not exiting

In a terminal, C-z suspends Emacs and returns you to the shell. Emacs is still there, with your unsaved work. Bring it back with:

bash
$ jobs
[1]+  Stopped                 emacs -nw notes.txt
$ fg

If you press C-z by accident and start emacs again, you end up with two copies.

Cancelling

C-g cancels a half-typed command or a prompt. It does not exit the editor.

The help system

All help commands start with C-h:

  • C-h t opens the tutorial.
  • C-h k then a key: describes what that key does.
  • C-h f describes a function (command).
  • C-h v describes a variable.
  • C-h a searches for commands matching a word.
  • C-h b lists the key bindings in effect.
  • C-h m describes the current modes.

For example, press C-h k and then C-x C-s. A help window explains that the keys run save-buffer.

If you remember a topic but no command name, use C-h a and type a word such as replace.

Closing the help window

Help often opens in a second window. Press C-x 1 to keep only the window you are in. If you moved into the help window, pressing q closes it.

Some terminals send the same code for Backspace and C-h. If a help key misbehaves, press F1 instead, as in F1 k.

Outside the editor

The shell command man emacs describes the startup options, and the GNU Emacs manual covers everything else. Inside Emacs, C-h r opens that manual if your distribution installed it. Some package it separately.

Try it

  1. Start emacs -nw notes.txt.
  2. Press C-h k, then C-a, and read the description.
  3. Press C-x 1 to close the help window.
  4. Press C-h a, type kill, and press Enter.
  5. Type some text, press C-z, run jobs, then fg.
  6. Press C-x C-c and answer the save question.

For a live Linux shell, there is the processes and cron lab.

Check your understanding

Emacs Exiting and Help

All 5 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.