0% found this document useful (0 votes)
36 views9 pages

Written Assignment - Unit 4

This document provides an introduction to using the Emacs text editor. It explains that Emacs has a main frame window containing buffers that display file contents. It outlines many useful keyboard shortcuts for navigating and editing text, and describes how to open, view, save and close files of different types in Emacs. While Emacs can view some binary files like images, other file types like videos appear as unintelligible text, since Emacs tries to read their binary data as plain text. The document recommends learning the most practical Emacs functions and commands for one's needs as a novice.

Uploaded by

Beetle999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views9 pages

Written Assignment - Unit 4

This document provides an introduction to using the Emacs text editor. It explains that Emacs has a main frame window containing buffers that display file contents. It outlines many useful keyboard shortcuts for navigating and editing text, and describes how to open, view, save and close files of different types in Emacs. While Emacs can view some binary files like images, other file types like videos appear as unintelligible text, since Emacs tries to read their binary data as plain text. The document recommends learning the most practical Emacs functions and commands for one's needs as a novice.

Uploaded by

Beetle999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Emacs for Novices

CS 3307: Operating Systems 2


Bayo Omoyiola
December 13, 2023
In this document, we will be going over the basics of Emacs. By the end, you should be

able to navigate Emacs, make sense of its many keyboard shortcuts, and work with files in the

editor. Please note that this guide will not be covering installation of Emacs, though you can find

installation instructions for your operating system here. Though Emacs can also be run in a

terminal, this guide will focus on the graphical user interface (GUI) version.

This is what you might see on screen when you first start Emacs. The main window in

Emacs is called a frame, so we will be referring to it as such (Kenlon, 2020). When we refer to a

window in Emacs, we are talking about the smaller panes within the frame, so it’s important that

we make that distinction early to avoid confusion. If this seems nonsensical and contrary to how
we use modern computer terminology, keep in mind that Emacs was around long before we

agreed on what should be called a “window”. While there is only one window shown in the

screenshot above, you can have multiple windows in the frame displayed horizontally and

vertically. Displayed in each window is a buffer, which will contain contents of whatever file

you have open and will also be where you type commands. By default, Emacs will start with the

*GNU Emacs* buffer, which can point you to many helpful resources. There is also a minibuffer

at the bottom, where you will be able to see the commands you type in. Like most programs,

there is the familiar menu bar at the top. While it is perfectly fine to use the menu bar, know that

Emacs can be entirely navigated through keyboard shortcuts. Whatever can be done from the

menu can also be done from your keyboard. Notice that next to most menu options, you can also

see the corresponding keyboard shortcut. Beneath the menu is the toolbar, which changes based

on what you are doing.

Keyboard Shortcuts

As you can see in the screenshot of the menu above, keyboard shortcuts in Emacs either

start with C or M. However, these are not referring to the C and M keys on your keyboard; they

really mean Ctrl and Alt. For example, to perform the shortcut for Undo (C-x u) you first hold
the Ctrl key while hitting the X key (written as Ctrl+X), then hit the U key. To Copy (M-w), you

would hit Alt+W. Here are a few other useful commands for editing and navigating an open file:

C-w Cut selected text


M-w Copy selected text
C-y Paste copied text
C-x h Select all text
C-v Scroll the whole screen down (Same as PgDn)
M-v Scroll the whole screen up (Same as PgUp)
C-l Center the screen on the current line
C-p Move up one line (Same as up-arrow)
C-n Move down one line (Same as down-arrow)
C-b Move back one character (Same as left-arrow)
C-f Move forward one character (Same as right-arrow)
M-f Move forward one word
M-b Move back one word
C-a Move to the beginning of the current line
C-e Move to the end of the current line
M-a Move to the beginning of the current sentence
M-e Move to the end of the current sentence
M-< Move to the beginning of the file
M-> Move to the end of the file

You may have noticed some shortcuts listed above can also be accomplished with single

keys on your keyboard. This is not done just for the sake of being redundant; Emacs is designed

to be compatible with a wide range of systems, including those that may lack things like arrow

keys. Even if your keyboard has the arrow and page keys, you may still find these commands

useful. The M-a and M-e shortcuts are especially useful for reading sentence by sentence, and
they’re a great demonstration of how Emacs can recognize human language units such as words

and sentences. There are many more commands to learn beyond the ones listed above, but these

should be enough to move your cursor around the screen. The *GNU Emacs* buffer you see at

startup contains links to tutorials and references that will help you get acquainted with keyboard

shortcuts.

Buffers

Whenever you open a new file in Emacs, the file you just had open doesn’t close. If you

go to the Buffers menu in your menu bar, you can see a complete list of your open buffers. You

can also use the C-x C-b command to open a buffer that contains a list of all open buffers, as

shown below.

To close a buffer, use C-x k.

Working with text files


Now that we’ve covered navigating through the buffers, let’s open a file. You can use C-

x C-f [filename] to open a text file and to create a new text file, depending on whether the

filename you type in exists or not. Let’s create a new text file, edit it, then save it.

After typing C-x C-f, you will notice down in the minibuffer that the command you

typed in turns into Find file: and auto-fills in the file path after it with whatever directory

you are currently working in. Since our example file text.txt does not exist yet, running this

command will create an empty text file in my current folder.

Once we are done editing our text file, use the C-x C-s command to save our changes. If

you glance down at the minibuffer, you’ll see a message that tells you the changes were written.

If you try to close the buffer for your text using C-x k while it has unsaved changes,

you’ll see a prompt in the minibuffer asking if you would like save your changes.
Working with different file types

While Emacs is primarily a text editor, it can also open other types of files. First, let’s run

through a quick explanation of the different file types. We can categorize files into two different

types. Text files are just that, files made up of plain text. These files can be read by any text

editor and include things like .txt files, config files, source code for software, and other types of

data stored as plain text. The other type, binary files, encompasses basically everything else. This

includes images, video files, and just about any file type you can imagine. Let’s see what

happens when we try to open different file types in Emacs.


Above we have screenshots of two different file types open in Emacs, a PNG image
file and an MP4 video file. Interestingly, opening an image file displays the image itself,
while viewing the video file shows us a mess of garbled text. You may notice some legible
text near the beginning that references the fact that this is an MP4 file. This is the header,
which also contains instructions that tell your computer how to read those files (Harsh,
2021). The rest of the gibberish is the data containing the video in the file, encoded in
binary code as a series of ones and zeroes. The reason why it doesn’t appear as ones and
zeroes here is because Emacs is trying to read that binary code as plain text, so it’s trying
to translate the data as such and showing us complete gibberish.
As we’ve seen, it is possible to open binary files in Emacs and in some cases even
view them. While Emacs can handle viewing some file types such as images, for other files
it will show us unintelligible strings of characters that are not all that useful.
Conclusion
In this guide, we have barely scratched the surface of what Emacs can do. There
are many more built-in functions, keyboard commands, and packages that can be
downloaded to extend Emacs even further. As a novice, don’t come away from this guide
thinking you have to memorize every single function and command to get use out of it.
You can get by just learning the functions and commands that are useful to you.
References
Harsh, K. (2021, February 9). What is a Binary File? Retrieved from Career Karma:
https://careerkarma.com/blog/what-is-binary-file/

Kenlon, S. (2020, March 10). Getting started with Emacs. Retrieved from Opensource.com:
https://opensource.com/article/20/3/getting-started-emacs

You might also like