Emacs is a powerful text editor designed for programmers. This quick introduction and reference guide is target at the new or casual user.
The following notation is used throughout:
means hold down the meta key and type the following character. The meta key is usually on the bottom left of the keyboard next to the spacebar.
This will only work on keyboards with a meta key.
However, on all keyboards you can use the ESC key. That is, hit the ESC key (DO NOT hold it down) and then the following key.
Two very important commands to remember as you learn Emacs are:
To enter the Emacs editor simply type emacs. To start Emacs with a particular file you can type: emacs filename.
Note: you may need to add some options to avoid opening a new X window. I typically run Emacs as:
emacs -nw --color=no
To begin working on a new file, say newfile, just type emacs newfile and the file will be created.
To exit Emacs you need to use the control sequence: C-x C-c
NOTE: it asks you in turn if you want to save each file that has been edited. If you do not save a file then any changes you made will be lost!
Emacs automatically creates backup files whenever a file is changed. When a file is opened a copy is stored in the file: filename~
If Emacs is aborted for any reason it will store the changed files to recover files in: #filename#
Whenever a file is opened, if there exist a #filename# that is newer than filename emacs will tell you:
Auto save file is newer; consider M-x recover-file
You can then use the command:
M-x recover-file \cr filename
to recover the file.
NOTE: The * means you will be prompted for further information and you must end the information with \cr.
In Emacs you can use the following commands to find and replace string patterns. When you use these commands, a prompt will appear at the bottom of the screen (referred to as the mini-buffer) where you enter the string.
Incremental search means that it will search for the characters as you type them. For example, if you typed find it would first find the next f, then it will find fi followed by fin and finally find.
query if every occurence of an old string should be replaced with a given new string
Each time you are prompted in the mini-buffer you can reply:
M-% is very useful because the user can check if the replacement is correct and try again if it is not.
In Emacs you can use the following commands to cut and paste text. Cut and paste commands involve the concept of a region.
A region is the area of text between the cursor and the last mark that was set.
When you first run Emacs you open one window and can only work on one thing at a time.
However, it is possible to work on two parts of the same file (for example to move --- or copy --- text from one part to the other) or to work on two different files at the same time.
To understand this you need to understand buffers.
The text you are editing in Emacs resides in an object called a buffer. Each time you visit a file (i.e., do emacs filename or C-x C-f filename) a buffer is created to hold the file's text.
At any time, one and only one buffer is selected (called the current buffer). If there are two or more buffers in use at the same time you can change the current buffer by C-x b buffer name.
By typing C-x 2 you split the one window into two windows --- each of which will show the same text. You can move each window to show a different part of the same buffer; then any change in one window changes the contents of the buffer and so the change also applies to the other window.
However, if each window is showing a different buffer then each window is completely independent. Text can still be copied or moved from one buffer to the other by cutting and pasting.
To do this you would split the window into two windows and then in one of the windows load another file. You can then move between the buffers with the C-x o command.
Emacs keeps track of what you are doing, and offers its best guess at what you want.
For example when you do C-x b it offers the name of the last buffer you were in as default.
Thus by simply repeating C-x b \cr you can toggle repeatedly between two buffers.
Emacs is the original Integrated Development Environment (IDE).
Emacs assumes you want to compile by using a make file and types make -k.
You can change the command that will be run, and it will be remembered for next time.
Emacs will split the window into two windows and show the output of the compilation in the second window. Note that Emacs will also ask you if you want to save each file that has been changed. If you do not save a file then the compilation will occur on the unchanged file!
If there are no errors you are done --- if there are errors they can be fixed in turn by typing C-x ` (NOT an apostrophe but a grave symbol --- i.e., a backward apostrophe).
Emacs will visit each file that has have error messages and put the cursor at the line of the next compilation error.
Simply fix this error and type C-x ` to go to the next error.
When all the errors have been corrected, type M-x compile again to recompile the program.
Author: | sjg@crufty.net |
---|---|
Revision: | $Id: emacs-intro.txt,v 59e0bded5705 2016-10-12 01:26:30Z sjg $ |
Copyright: | Crufty.NET |