emacs
(for the purposes of this introduction we will be using the lightweight mg
micro version of emacs. To install the editor run the following commands:
sudo apt -y install mg
Running mg
creates a window on our screen containing:
- Text window showing the contents of the buffer
- A one-line mode line describing what is going on in the text window
- A minibuffer -- a special location to input commands
mg
relies heavily on the escape key and the control key. Throughout this section, <esc>
means to type the escape key and <cntl>
. For example.
<esc> a
<cntl>-a
Means type the escape key and then the a
key, which is sometimes referred to as an escape sequence and the second one is hold down the control key and then press the a
key while holding the control key. This is known as a control character. If you don't do this the text is inserted into the buffer.
The character operations are:
cntl-b
: Move back one charactercntl-f
: Move forward one charactercntl-p
: Move to the previous linecntl-n
: Move to the next linecntl-d
: Delete the character underneath the cursordelete
: Delete the charater to the left of the cursorcntl-t
: Transpose the two previous characters.
The file operations are:
cntl-x cntl-v
: Visit a file -- putting the contents of a file into the buffercntl-x cntl-w
: Write the contents of the buffer to a filecntl-x cntl-s
: Write the contents of the buffer to the file listed in the mode line
To exit mg
, use the following control sequence:
`cntl-x cntl-c`
Line operations work with an entire line of the buffer. The four line operations are:
cntl-a
: Move the cursor to the beginning of the linecntl-e
: Move the cursor to the end of the linecntl-o
: Insert a blank line into the buffercntl-k
: Kill a line of text
Word operations work with an entire word of text at one time instead of just one character at a time.
<esc>b
: Move back one word<esc>f
: Move forward one word<esc><delete>
: Delete one word to the left<esc>d
: Delete one word to the right<esc>t
: Transpose the two words around the cursor<ecs>c
: Capitalize a word. Must be at the beginning of a word for this to work consistently<esc>u
: Convert a word to uppercase<esc>l
: Convert a word to lowercase
This practice is a minimal introduction to how to use emacs. Using your preferred search engine explore the use of emacs if this has scratched a surface. How to get comfortable with emacs would be a workshop in itself.
- I used this Guide to emacs to write this document
- A former colleague recommended Mastering Emacs as a good way to start with good habits