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
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.
- The Editor of A Lifetime by Perry Metzger
- Emacs for Writers by Jay Dixit
- CppCon 2015: Atila Neves "Emacs as a C++ IDE" by Atila Neves
- Emacs as a Python IDE by Drew Werner
- EmacsConf 2015 - Hearing from Emacs Beginners by Daniel Gopar
- http://emacsrocks.com, a website dedicated for Emacs intro and tutorial videos (all videos are downloadable), by @emacsrocks.
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.
- Fire up Emacs.
- Type keystroke C-x C-f (read: Ctrl-x Ctrl-f).
- See the most bottom line of Emacs screen, there is a minibuffer saying Find File: ~/ and a blinking cursor.
- Type your filename such as myfile.c and press Enter.
- Then Emacs screen changes to show you the new file. Type on the screen to write the text.
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:
- Official GNU Emacs Manual
- Official GNU Emacs Manual [pdf]
- Official GNU Emacs List of References
- Absolute Beginner's Guide to Emacs by Jess Hamrick
- Emacs Mini Manual by Tuhdo
- Emacs Discussions at StackoverFlow
- Emacs Beginner HOWTO [pdf] by Jeremy Zawodny
- Emacs Newbie [wiki] by EmacsWiki