Catriona Rasdale
emacs
editing using emacs
Commands | Navigating | Searching | Editing | Saving / Quitting
Emacs is a server-side, command line text editor, meaning you can edit files on the server and see changes instantly. This can be a powerful & time-saving tool, and well worth learning - however it would be recommended that back-up copies of files be made if using emacs for the first time!
You can do this with the Unix 'cp' command, which will make another copy of a specified file e.g.
$ cp default.shtml default_backup.shtml
This will create a new 'default_backup.shtml" with the original content. You can then use the command
$ emacs default.shtml
to modify your file, with a backup available if everything goes horribly wrong. To open the emacs program without having to open a file, just use the command:
$ emacs
And to open a file in emacs, the following format is used:
$ emacs filename.extension
So for example:
$ emacs default.htm
Commands
Here is an explanation of the terminology used here (including some example commands):
Ctrl-a : Hold down the Control key and a together
Esc > : Hit the Escape key & release, and then >
SPC : Spacebar
DEL : Delete key
RTN : Return key
With a double keypress command, for example Ctrl-x Ctrl-c, you don't have to release the Ctrl key, you can keep this depressed.
How to navigate your file
Esc < : Go to the top of the file
Esc > : Go to the bottom of the file
Ctrl-a :Go to the start of the line
Ctrl-e : Go to the end of the line
Esc f : Forward word (move to next word)
Esc b : Backwards word (move to previous word)
Searching
Ctrl-r : Reverse search (search back through the file)
Ctrl-s : Forward search (search forward through the file)
Editing
Ctrl-x Ctrl-u : Undo the last action
Ctrl-SPC : Mark start of selection
Esc w : Copy from start of selection to cursor point
Ctrl-k : Cut / 'kill' line from cursor point to end
Ctrl-y : Paste, or'yank' content copied using Ctrl-spacebar & Esc w, or 'killed' using Ctrl-k
Ctrl-x i : Insert file from the same directory as the file you are editing
Ctrl-x Ctrl-f : Find-file or edit another file - you will be asked for the filename
Esc % : Find piece of text to replace. Upon prompt, actions are:
- SPC : Perform this replacement
- DEL : Don't perform this replacement
- RTN : Terminate without performing this replacement
Saving and quitting
Ctrl-x Ctrl-s : Save file
Ctrl-x Ctrl-w : Save file to different name
Ctrl-x Ctrl-c : Quit file
News with emacs
Group buffer commands | Summary buffer commands | Article buffer commands
As well as a text editor, emacs has a newsreader function called gnus. This allows you to read newsgroups and post messages.
To connect to a server, you should place the following into a file called .emacs at the root of your home directory:
(setq gnus-select-method
'(nntp "Your news server"))
(setq user-full-name "Your own name")
(setq user-mail-address "Your email address")
To use gnus, enter emacs as normal:
$ emacs
then use the command
Esc x gnus
There are three buffers within gnus: the newsgroup buffer, the summary buffer and the article buffer.
The newsgroup buffer usually contains a list of newsgroups to which you subscribe and which have unread articles. You will be shown how many unread articles there are in each group. Use the arrow keys and RTN to view a particular newsgroup.
The summary buffer is where you can view a list of articles within the newsgroup selected. Again use the arrow keys and Enter to view an article.
The article buffer is where the text of the selected message is displayed.
Group buffer (to view & select newsgroups)
A progressive look at commands, in the order you may need them:
A A : List all newsgroups available on the server
A k : View all 'killed' files (see Ctrl-k below)
A z : View all zombie groups (new groups which come to exist on the server)
S s : If you know the name of the newsgroup you want,
you can use this to find it instead of
A A to list all
u : Subscribe/unsubscribe to the selected group
Ctrl-s : Search for a newsgroup to view within list
L : View all subscribed-to newsgroup (usually you are only shown those with new articles)
l (ell) : View only groups with unread articles
g : Check a group for new news
SPC : View the first unread article in the selected group
DEL : Move to the previous group containing unread articles
Ctrl-k : Kill selected group, not to be shown at startup again.
Summary buffer (to select messages)
RTN : Read selected article
s : Search within selected article for text-string
Ctrl-s : Search for text-string
n : Move to next unread article
p : Move to previous unread article
a : Post new article (make new thread)
f : Reply to selected article, without quoting original
F : Reply to selected article, including original text
r : Reply to selected article via email without quoting
R : Reply to selected article via email, including original text
C : Cancel article after it has been posted to the group
c : Catch up with newsgroup (mark all items read)
Esc u : Mark selected item unread
q : Quit back to group buffer
Article buffer (to view & compose messages)
SPC : Display & scroll through selected article, or onto next article if at the end
DEL : Scroll backwards through the article
Ctrl-c Ctrl-c : Send article (to group or via email)
Ctrl-x k : Quit writing message without sending