FactorPad
Faster Learning Tutorials

Linux emacs command summary with examples

emacs allows you to edit text files.
  1. Purpose - Learn what emacs is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with emacs.
  4. A tip - Finish off with one more insight.
Paul Alan Davis, CFA, October 30, 2016
Updated: August 3, 2018
In this tutorial, 56 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Next

~/ home  / tech  / linux essentials  / emacs command


The Linux emacs command

Beginner

Learn the basics of one of many text editors at the Linux command line.

Video Tutorial

Linux emacs command summary with examples (3:33)

Videos can also be accessed from the YouTube Playlist.

Video Script

The Command and Why You Need It

Our fifty-sixth word, or command to memorize is emacs from our category Text.

emacs allows you to edit text files.

Recall from video 20 on nano, our first text editor, it offered a simple tool for quick edits, but for added functionality, most people use a program like emacs, or vim, which we'll be introducing in our next video (tutorial).

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The emacs command has over 50 options and the argument is a text file to edit, and because emacs is a full-blown text-editing program, its list of internal commands is vast.

Like most commands, help is available with double-dash. Once inside emacs view internal help with Ctrl-h then r. And importantly, to quit, type Ctrl-x then Ctrl-c.

So why is emacs an important command? Well, programmers spend lots of time in editors, memorizing commands, and you'll need to find your go-to editor. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go. Let's start with the emacs --help option, and redirect that > to a file called video56.txt.

$ emacs --help > video56.txt

Next, type emacs and that filename video56.txt.

File Edit Options Buffers Tools Text Help Usage: emacs [OPTION-OR-FILENAME] ... Run Emacs, the extensible, customizable, self-codumenting real-time display editor. The recommened way to start Emacs for normal editing is with no options at all. Run M-x info RET m emacs RET m emacs invocation RET inside Emacs to read the main documentation for these command-line arguments. Initialization options: --batch do not do interactive display; implies -q --chr DIR change to directory DIR --daemon start a server in the background --debug-init enable Emacs Lisp debugger for init file --display, -d DISPLAY use X server DISPLAY --no-desktop do not load a saved desktop --no-init-file, -q load neither ~.emacs nor default.el --no-shared-memory, -nl do not use shared memory --no-site-file do not load site-start.el --no-site-lisp, -nsl do not add site-lisp directories to load-path --no-splash do not communicate with X, ignoring $DISPLAY --quick, -Q equivalent to: -q --no-site-file --no-site-lisp --no-splash --script FILE run FILE as an Emacs Lisp script -UU-:----F1 video56.txt Top L1 (Text) -------------------------------- For information about GNU Emacs and the GNU system, type C-h C-a.

Here it is, use PgUp and PgDn to scroll.

Here I only have time for a quick flyby. But there are options here, as you can see, for initializing the program (above).

File Edit Options Buffers Tools Text Help -q --no-site-file --no-site-lisp --no-splash --script FILE run FILE as an Emacs Lisp script --terminal, -t DEVICE use DEVICE for terminal I/O --user, -u USER load ~USER/.emacs instead of your own Action options: FILE visit FILE using find-file +LINE go to line LINE in next FILE +LINE:COLUMN go to line LINE, column COLUMN, in next FILE --directory, -L DIR prepend DIR to load-path (with :DIR, append DIR) --eval EXPR evaluate Emacs Lisp expression EXPR --execute EXPR evaluate Emacs Lisp expression EXPR --file FILE visit FILE using find-file --find-file FILE visit FILE using find-file --funcall, -f FUNC call Emacs Lisp function FUNC with no arguments --insert FILE insert contents of FILE into current buffer --kill exit without asking for confirmation --load, -1 FILE load Emacs Lisp FILE using the load function --visit FILE visit FILE using find-file Display options: --background-color, -bg COLOR window background color --basic-display, -D disable many display features; used for debugging Emacs -UU-:----F1 video56.txt 26% L25 (Text) ---------------------------------

Taking actions (above) and changing displays.

Okay, then, to quit, type that combination Ctrl-x and Ctrl-c.

$ emacs --help > video56.txt $ emacs video56.txt $ _

And then one last thing, why don't we head back in (using emacs) without an argument.

File Edit Options Buffers Tools Help Welcom to GNU Emacs, one component of the GNU/Linux operating system. Get help C-h (Hold down CTRL and press h) Emacs manual C-h r Browse manuals C-h i Emacs tutorial C-h t Undo changes C-x u Buy manuals C-h RET Exit Emacs C-x C-c Activate menubar M-` (`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key. If you have no Meta key, you may instead type ESC followed by the character.) Useful tasks: Visit New File Open Home Directory Customize Startup Open *scratch* buffer GNU Emacs 24.4.1 (x86_64-pc-linux-gnu) of 2015-03-07 on trouble, modified by Debian Copyright (C) 2014 Free Software Foundation, Inc. GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details. Emacs is Free Software--Free as in Freedom--so you can redistribute copies of Emacs and modify it; type C-h C-c to see the conditions. Type C-h C-o for information on getting the latest version. -UUU:%%--F1 *GNU Emacs* All L1 (Fundamental) -------------------------- For information about GNU Emacs and the GNU system, type C-h C-a.

And this will show you an opening screen with a list of helpful resources, like manuals and a tutorial. Okay, very good.

A Final Tip

Okay now you know how to use emacs. And you know the syntax for commands, options and arguments.

One last tip about the vast emacs command. So I should mention, most people use a text editor within their GUI, instead of the terminal. Just a quick comment there.

Okay, thanks for visiting today. I hope this was a helpful introduction to the emacs command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

If this quick summary was helpful, please consider subscribing to our growing YouTube Channel. Click here.

  • For the Outline to all 100 tutorials, click Outline.
  • To go back to the more command, hit Back.
  • Our review of editors is quick. You'll need to spend a few days with each one to see what works best for you. Next up is our summary of vim.

Outline Back Next

~/ home  / tech  / linux essentials  / emacs command



 
 
Keywords:
linux emacs command
linux emacs
emacs exit
emacs shell
emacs tutorial
linux text editor
emacs tutorial
close emacs
linux emacs examples
gnu emacs
emacs find
emacs help
exit emacs
emacs terminal
emacs text editor
emacs commands
gnu emacs
linux editor emacs