Did you ever wonder if there is a text editor that can do anything almost like a complete operating system? That text editor is GNU Emacs. Emacs is truly lightweight (console is its default interface), long-living (since 1976; 40 years ago), extensible, advanced, very general purpose, and Emacs makes the user types very fast as an Emacs user ever said "you type on Emacs as fast as you think". As a text editor, Emacs can do any basic text editing, edit source code for any programming language, do multitasking such as writing while compiling, and more. Emacs is highly configurable through its Lisp system and extensible by a huge number of extensions available. Emacs has both console and GUI interfaces, while the user can choose what interface to use at anytime. Emacs official website is http://gnu.org/software/emacs. This article introduces GNU Emacs for complete beginners using Ubuntu operating system. This article flows starting from installing, navigating, windowing, basic multitasking, and basic keystrokes of Emacs.
Subscribe to UbuntuBuzz Telegram Channel https://telegram.me/ubuntubuzz to get article updates directly.


About Emacs

GNU Emacs is a part of GNU operating system, just like GNU coreutils (containing ls, cp, mv, rm, dd, du, etc.) or GNU Compiler Collection (containing gcc and g++), except Emacs is the GNU text editor. Emacs is head-to-head similar to vi as a console text editor, and also Vim as a modern vi successor, by emphasizing keyboard strokes to do all aspects of editing. Thus, Emacs is a non-mouse text editor, so the user is basically supposed to learn its keystrokes like C-x C-s or M-x compile and so on.

Some Good Videos Introducing Emacs

There are many good Emacs users creating introduction videos for it. Believe me, they introduce Emacs very well, so even beginners can understand the explanations. I suggest you to visit these videos to have great understanding of Emacs.

Installing Emacs

To install GNU Emacs in Ubuntu, use apt command to download it from official repository. The latest version at 22 November 2016 is 24.

$ sudo apt-get install emacs

Running Emacs

Console mode: to run Emacs in default mode (console), perform this command line:

$ emacs --no-window-system
$ emacs -nw

GUI mode: to run Emacs in graphical mode (e.g. enabling click, enabling LaTeX Preview Pane), perform this command line:

$ emacs

Basic Keys

Emacs understands these basic keys and their abbreviations:

M = Esc
C = Ctrl
S = Shift
M-x = Esc-x
C-x = Ctrl-x
C-x C-c = Ctrl-x Ctrl-c
C-x o = Ctrl-x o
M-x compile RET = Esc-x and then type "compile" and then press ENTER

Interface Overview

This is Emacs user interface in default mode (Terminal mode) from inside a Terminal:

This is Emacs user interface in GUI mode with its own window. Notice the title bar: the program name "emacs24" and the computer name "@master"; and the menu bar File, Edit, Options, etc.

This is Emacs menu, associated with F10 key. This is your keystrokes reminder, when you forget some Emacs shortcut keys, just open the menu and look at the corresponding item/command.

You can find Emacs program on the Ubuntu Menu as two icons, GUI mode and Terminal mode. And you can place the icon on the Ubuntu Launcher on the left like this.

Creating New File

Here is how you start with Emacs for the first time.

  1. Fire up Emacs. 
  2. Type keystroke C-x C-f (read: Ctrl-x Ctrl-f).
  3. See the most bottom line of Emacs screen, there is a minibuffer saying Find File: ~/ and a blinking cursor.
  4. Type your filename such as myfile.c and press Enter.
  5. Then Emacs screen changes to show you the new file. Type on the screen to write the text.
Tip: if you forget the keystroke C-x C-f, create a new file by using menu: press F10, select File > Visit New File C-x C-f.

1. Navigating

Moving cursor arrow keys (left, bottom, right, up)

Selecting/highlighting text S-arrow

Selecting/highlighting text S-C-arrow

Copy M-w

Cut C-w

Paste C-y

Erase Backspace

Delete Del

Open Menu F10

Cursor jump to beginning of line C-a

Cursor jump to end of line C-e

Quit Emacs C-x C-c

Cancel an action or a command C-g

2. Saving

Save C-x C-s

Save as C-x C-w

Open file C-x C-f

Create new file C-x C-f

3. Windowing

Split horizontally C-x 2

Split vertically C-x 3

Jump to next window C-x o

Close window C-x 0

4. Compiling

This section introduces an example about user multitasking in Emacs, which is compiling C program with gcc and runing the program; done by splitting window and running each task in each window.

First, write a source code in C language with the filename myfile.c.

Second, M-x compile RET gcc myfile.c -o myfile

Third, C-x 3

Fourth, C-x o

Fifth, M-x shell RET

Fourth, type shell command line ./myfile

Further Reading

There are good references available on the net freely (as in freedom and as in price) about Emacs for beginners. Here I list some of them:

, , , ,