
Writing Prose with Emacs

Peter Prevos |
3043 words | 15 minutes
Share this content
Emacs is known as an extensible text editor, but this is a confusing description to authors. Computer programmers refer to writing code as editing, while for an author, the term editing refers to the last stage in the writing process. A text editor is a tool to write text for computers to read. However, Emacs can be a tool for editing code and writing for humans.
This article explains the basics of how to write prose using Emacs as an advanced typewriter. This article is part of Emacs Writing Studio, which explains how to use Emacs to undertake research and write and publish articles, books, and websites.
Emacs Writing Studio
A comprehensive guide for writers seeking to streamline their workflow using Emacs. The book covers everything from organising ideas and writing distraction-free to publishing in multiple formats. It’s perfect for both beginners and experienced Emacs users, offering practical tips and a tailored configuration to enhance your writing process.
The source files of the book and EWS configuration are also freely available on GitHub.
Writing modes
Emacs is like a Swiss Army knife in that it can undertake several different functions through so-called major modes.
An Emacs major mode controls how a buffer (the currently open file) behaves. A text file could be a movie script, a to-do list, the next great novel, computer code, or however you express your creativity. In commercial software, each file could be a different file type that you can only read in specialised software. Emacs automatically recognises the type of file you open and modifies its behaviour accordingly.
In Emacs, text mode is for simple text files. Fountain mode helps you write movie or theatre scripts. Org mode excels at managing your to-do lists and creative writing. Many other modes with specialised functions are available in the package repositories.
Each buffer can only have one major mode operating at a time, but it can have several minor modes. A minor mode provides optional extras, such as Flyspell, for on-the-fly spell checking.
Org mode is arguably the most versatile major mode in Emacs. A large portion of these articles describe how to use this package.
The remainder of this article focuses on the principles that apply to all text modes.
Basic principles
The foundational major mode for writing prose is text-mode
. Emacs documentation describes it as the mode for writing text for humans to read, in contrast to prog-mode
, which is for writing code that computers read. Text mode forms the foundation for all other prose formats. This means that all these modes use the same basic functionality for writing.
The basic principle of writing in Emacs is easy: you just start. However, some differences exist between standard word processors and the Emacs way. Once you get used to the convenience of writing in Emacs, you never want to use other software again, as you will miss the extensive editing functionality to jump around your text with ease.
Moving around in a buffer
You can move the cursor with arrow keys and other standard navigation keys. Emacs documentation sometimes refers to the cursor as a point; technically, the cursor is the character displayed on the screen (a line or a box), and a point indicates where the next typed character will appear. In most situations, the terms cursor and point are used interchangeably.
In addition to the standard methods to move around a buffer, Emacs provides additional functionality to help you navigate your project. For example, C-p
(previous-line
) does the same as the up key (see table below). Some people prefer these keys so their hands can stay in the default position for fast touch-typing. However, writing is more about thinking than maximising keystrokes per minute, but feel free to try them out.
Direction | Function | Key |
---|---|---|
Left | left-char |
C-b , <left> |
Right | right-char |
C-f , <right> |
Up | previous-line |
C-p , <up> |
Down | next-line |
C-n , <down> |
Previous word | backwar-word |
M-b , C-<left> |
Next word | forward-word |
M-f , C-<right> |
Scroll down | scroll-down-command |
C-v , <PageDown |
Scroll up | scroll-up-command |
M-v , <PageUp> |
Start of line | move-beginning-of-line |
C-a , <home> |
End of line | move-end-of-line |
C-e , <end> |
Start of buffer | beginning-of-buffer |
M-< , C-<home> |
End of buffer | end-of-buffer |
M-> , C-<end> |
Making a mark
You will undoubtedly have the experience of moving from one part of a document to another and then like to jump back but lose your place, so you search through the document to get back to where you left off.
In Emacs, you can save the cursor's current position with C-space
, which marks the current location of the point. You can now move to another part of your document, edit or read what you need, and jump back with C-u C-space
.
Focusing
Getting lost in a sea of words on your screen is easy. Some simple keystrokes can help you to focus your eyes quickly. Keying C-l
(recenter-top-bottom
) moves the line that your cursor is on to the centre of the screen.
If you repeat this keystroke, the cursor will move to the top of the screen. If you do this three times in a row, the cursor moves to the bottom of the screen.
Copying and pasting text the Emacs way
The most apparent difference between Emacs and typical word processors is that it does not use the standard Common User Access (CUA) keys standard for selecting, copying, cutting and pasting text used in modern applications. But the trade-off for the minor inconvenience of learning a new method to edit text is that the Emacs way is much more versatile than other software.
Selecting text
With the shift and arrow keys, you can select text in almost all major modes. Because the shift and arrow keys in Org mode are reserved for editing lists, you must use a more advanced way to select a text block. You first set a mark with C-space
and then move to the end of the section to select your text, which is highlighted.
To select a complete paragraph, use the M-h
key. Repeatedly pressing M-h
will select subsequent sections. Using C-x h
will select all text in the buffer.
Once the text is marked, you can act on this block by deleting, copying or moving it.
Copy and paste text
In modern computing language, copying and pasting are handicraft analogues for moving text from one place to another. Emacs terminology is more evocative. Copying a text is the same as saving it to the 'kill-ring' and yanking a text retrieves it from that seemingly bleak location.
While the clipboard in most systems only retains the last entry, the kill ring provides access to a history of killing actions. In other words, Emacs stores a history of all text you copy and cut from a buffer to the kill ring. The length of this history is stored in kill-ring-max
, which is 60 entries by default. Once the kill ring is full, the oldest item vanishes. Emacs erases the content of the kill ring when you exit the program. Use the following keyboard shortcuts to copy and move the text to and from the kill ring:
Shortcut | Function | Description |
---|---|---|
M-w |
kill-ring-save |
Copy a selection to the kill ring |
C-W |
kill-region |
Move a selection to the kill ring |
C-y |
yank |
Paste the most recent entry in the kill ring to the buffer |
M-y |
yank-pop |
Replace the previously yanked text with the next kill ring entry |
The kill*
commands copy or move text to the kill ring and the system clipboard. The yank*
commands copy an entry from the kill ring to the current buffer. The yank-pop
(M-y
) command cycles through the contents of the kill ring so you can access the history. When you use advanced completion systems, you see a list of all available previous selections in the minibuffer. Use the arrow keys or search to pick what you like to yank into the active buffer.
If you prefer using the familiar keyboard shortcuts, enable cua-mode
for convenience. With this mode, you can use C-z
, C-x
, C-c
, and C-v
to undo, cut, copy, and paste in addition to the standard Emacs bindings. The C-x
and C-c
keys only activate when you mark a region. You can enable this mode by adding (cua-mode t)
to your init file. This mode is not enabled in the Emacs Writing Studio configuration.
Search and replace
The most common search method in Emacs is incremental. An incremental search (C-s
) begins searching as soon as you type the first character of the search string. As you type in the search term, Emacs shows you where the term is found. When you have typed enough characters to identify the place you want, you can terminate the search explicitly with ENTER
or C-g
.
The C-s
shortcut searches incrementally from the cursor. You cycle through the search results by repeatedly pressing C-s
. Using C-r
searches the text before the cursor.
Emacs saves search terms in the search ring. Typing C-s C-s
will show the previous search term. Using C-p
and C-n
lets you scroll through previous search terms.
To search and replace text in a buffer, use M %
and follow the prompts in the mini buffer.
Correcting mistakes
The most convenient aspect of writing on an electric screen is that it is easy to change your mind or correct a mistake without having to resort to correction fluids or other archaic methods. The following basic editing commands are available to modify text. Please note that commands that start with kill
store the deleted text on the kill ring.
Action | Function | Key |
---|---|---|
Delete character after point | delete-char |
C-d , <delete> |
Delete character before point | delete-backward-char |
<backspace> |
Delete the next word | kill-word |
M-d , C-<delete> |
Delete to the end of the line | kill-line |
C-k |
Besides removing unwanted characters, you can also swap them with a series of transposing commands. When you accidentally reverse two letters in a word, you can switch their order with the transpose-char
command with the cursor between them (C-t
). Swapping words is quickly done with the transpose-words
(M-t
) command.
Undo the Emacs way
The Emacs undo
command is mapped to C-/
. If you need to undo the step, use C-?
(undo-redo
). Each consecutive command will undo earlier changes. Any command other than an undo command breaks the sequence.
Although each editing command usually makes a separate entry in the undo records, simple commands (single key press) may be grouped together.
The Emacs undo system recovers any past text version. In contrast, the standard undo/redo system can lose past edits as soon as you redo. Getting lost in a sequence of undo and redo commands is easy. The Undo Tree package by Toby Cubitt helps you keep track of your changes by visualising them as a tree. Use the ~ undo-tree-visualise ~ (C-x u
) command to walk through previous versions of your text.

The current buffer will change as you work your way through its history with the arrow keys where x
marks the spot of the selected step. Use q
to select the chosen edit and continue writing. The C-q
chord jumps out of the undo tree without making changes.
(use-package undo-tree
:config
(global-undo-tree-mode)
:custom
(undo-tree-auto-save-history nil))
There is also a nuclear option. You can discard all the changes since the buffer was last visited or saved with M-x revert-buffer
, which reloads the file from the disk.
Configure text modes
The original purpose of Emacs is to edit computer code, so by default, the editor does not wrap lines at the end of the screen. While this behaviour is great for developing software, it isn't very pleasant for writing prose. The visual-line-mode
minor mode enables line-wrapping, which is common in word processors. You can run the function separately for each buffer, but ideally, you link (hook) it to all text modes.
The second change is that when you select (mark) a section of text and start typing, Emacs will not replace the selected text by default. To enable Emacs to overwrite selected text, you set the delete-selection-mode
variable, as below.
Another sensible default for authors is to ensure that Emacs lets you use the page-up
and page-down
buttons to go all the way to the first and last line in the buffer.
The last line better integrates the system clipboard with the Emacs kill ring.
;; Sensible line-breaking
(add-hook 'text-mode-hook 'visual-line-mode)
;; Overwrite selected text
(delete-selection-mode t)
;; Scroll to the first and last line of the buffer
(setq-default scroll-error-top-bottom t)
;; Copy the system clipboard to the kill ring
(setq save-interprogram-paste-before-kill t)
Checking spelling
The Emacs minor mode Flyspell provides an interface to the Hunspell spell-checking software. To enable spell-checking, you thus first need to ensure that Hunspell is available on your computer. Hunspell is easy to install on Linux computers but is also available for Windows and Chromebook.
The configuration below enables Flyspell for all text modes and sets Hunspell as the default checking program. The M-F7
key checks the spelling for all words in the buffer, and F7
checks the word on which the cursor is standing.
A more productive method is to use the flyspell-auto-correct-previous-word
(C-;
) function. This function provides the most likely correction of the first spelling error before the cursor. Emacs will show the list of possible corrections in the mini buffer. Repeatedly pressing C-;
will cycle through the options until you return to the original. This function prevents you from having to jump to your spelling mistakes.
;; Spell-checking
;; Requires Hunspell
(use-package flyspell
:custom
(ispell-program-name "hunspell")
(ispell-default-dictionary "en_AU")
:hook (text-mode . flyspell-mode)
:bind (("M-<f7>" . flyspell-buffer)))
(use-package flyspell-correct
:after (flyspell)
:bind (("C-;" . flyspell-auto-correct-previous-word)
("<f7>" . flyspell-correct-wrapper)))
You must modify the configuration to set your preferred dictionary as the default. The available English dictionaries in Hunspell are:
en_US
(American)en_CA
(Canadian)en_GB
(British)en_AU
(Australian)
Hunspell supports a lot of other dictionaries, so you can install and choose your own when English is not your preferred language.
If you are multilingual, you can set a different language for each buffer by adding a file variable to the relevant buffer. Ass the text below as the last lines in your Org mode file, where you replace nederlands
(Dutch) with your preferred language:
,# Local Variables:
,# ispell-local-dictionary: nederlands
,# End:
Emacs evaluates this line and activates the dictionary when you run M-x normal-mode
and the next time you open the file. This dictionary only applies to the relevant file; all other buffers remain in the default language.
Counting words
To count the words in a buffer, or part thereof, use the count-word-region-function
, which is bound to M-=
.
The result appears in the minibuffer. When you select a portion of text, this function will count only the selection. Adding the C-u
, prefix counts the words for the hole buffer (C-u M-=
).
For Org mode buffers, the ews-org-count-words
command counts the words in each section and adds the word count as a property. Refer to Distration-Free Writing with Org mode for details.
Text size
To temporarily increase the height of the text in the current buffer, type C-x C-+
. To decrease it, type C-x C--
.
To restore the default (global) face height, type C-x C-0
. These keys are all bound to the text-scale-adjust
function, which looks at the last key typed to determine which action to take.
Text Completion
Emacs developers have also written many completion systems to help you write text. These packages fall into two categories: minibuffer completion and expansion systems for prose and code.
Expanding text in human languages comes in two forms. You either start typing a word, and Emacs predicts what should go next, or you write a predefined abbreviation that expands into a word, a paragraph, a table or whatever else you define it as.
Predictive text is one of these technologies that can be both a blessing and a curse. Use it cautiously because it can hinder your writing when used too eagerly.
Company mode is a versatile package that can help you with completing long words. Its primary purpose is to assist developers with writing code, but it can also help you complete words.
Company mode provides suggested completions in a dropdown menu whenever you type a defined number of characters. It derives these options from all open text buffers. Use the arrow keys and enter to select your option, or ignore the menu and keep typing.
This configuration only activates when entering at least four characters and only shows words of eight or more letters. The wraparound option lets you cycle through the completions menu with the down and up arrow keys.
;; Auto completion
(use-package company
:custom
(company-minimum-prefix-length 4)
(company-dabbrev-minimum-length 8)
(company-selection-wrap-around t)
:init
(global-company-mode))
When using variable pitch fonts, the dropdown menu for text completion gets distorted because the letters are not all the same size. The company-posframe package by Tumashu solves this problem. A post frame is a floating child frame that can pop up anywhere on the screen, usually to show additional information.
;; Required for variable pitch
(use-package company-posframe
:config
(company-posframe-mode 1))
Emacs Writing Studio
If you like to support my work, then please purchase the Emacs Writing Studio book.
Emacs Writing Studio
A comprehensive guide for writers seeking to streamline their workflow using Emacs. The book covers everything from organising ideas and writing distraction-free to publishing in multiple formats. It’s perfect for both beginners and experienced Emacs users, offering practical tips and a tailored configuration to enhance your writing process.
Emacs is a malleable system, and everybody has personal preferences on how to undertake a task and configure Emacs. Any article on how to use Emacs is thus opinionated. If you have a different way of doing things, please complete the contact form to send me an email or contact me on social media.
Emacs is a malleable system, so everybody will have their personal preferences. Any article on how to use Emacs is thus opinionated. If you have a different way of doing things, please complete the contact form to send me an email or contact me on social media.
The next article dives into getting productive with Emacs by explaining how to improve the Emacs user interface.
Share this content