table of contents
- expected learning outcomes
- getting started
- creating and editing files
- cut or copy and paste text
- rectangular editing
- to work with two files in two different emacs panes
- find and replace
- create keyboard macro
expected learning outcomes
The objective of this activity is to promote understanding of basic emacs commands, and it is structured as a command reference for better continued learning effectiveness.
There are several text editors that create plain text files, such as emacs, vi and pico. Unless you are already familiar with vi or pico, we recommend that you use EMACS (Editor MACroS), known simply as emacs. We strongly recommend that you study the emacs tutorial, which you can easily start from within emacs.
getting started
In emacs you use combinations of special keys and character keys to invoke commands. The commands usually involve either the CONTROL key (CTRL or CTL) or the META key (ESC on MAC or ALT, EDIT on others). Therefore, Ctrl-h (or C-h) means that you press the CONTROL and h key together, while Ctrl-h t (C-h t) means that you press the CONTROL and h keys, then release both keys and tap t.
To start the emacs tutorial:
To get help in emacs:
To exit emacs, type:
To exit an emacs command, type:
Very Important Command:
View the emacs Command Summary
creating editing files
To open and edit a file in emacs, simply type
(myfile can be a new or an existing file)
To save a file:
To save as:
To choose a file from the current directory:
To move within your file in emacs:
To navigate by page and file:
cut or copy and paste text
Complete lines of text:
rectangular editing
This is useful for editing vertical blocks of text, such as removing characters in an alignment or removing tags at the beginning of lines, etc.
to work with two files in two different emacs panes:
find and replace
There are two types of search and replace functions in emacs. The queried search and replace will find the text and then ask you if you want to change it, whereas the unconditional search will find all occurrences of the text and replace it without asking you.
To perform an unconditional search and replace:
Then type replace string and tap return, followed by the text you want find (return), and the text you want to replace it with.
To perform a queried search and replace:
Emacs will prompt you for the text you would like to find as well as the text to replace it with, then it will find each occurrence of the search string as ask what you would like to do.
Here are some options:
create keyboard macro
Sample file for demonstration: