Writing a book in VS Code

VS Code is a genuinely good place to write a book, because a manuscript is plain text and VS Code is very good at plain text — Git history, search across chapters, no proprietary format, no cloud dependency. What it will not do is produce the book: its Markdown preview is a web page, and printing a web page gives you a document, not a typeset volume.

The idea sounds wrong for about a day. Then you notice that a book is a folder of text files, that you want to know what changed since Tuesday, that you want to search 90,000 words in 40 milliseconds, and that you would rather not find out in 2031 that your writing app's format is no longer readable.

Novelists have been quietly doing this for years. Here is the setup that works, and — more usefully — the point at which the editor hands off.

Why a code editor suits a manuscript

  • The files are yours. Markdown on your disk. No account, no export step, no format to be locked out of.
  • Real version history. Git gives you every draft, a diff of what changed in a scene, and the ability to write a risky rewrite on a branch and throw it away without ceremony.
  • Search that scales. Find every use of a character's name across the whole book, with a regex if you need one, instantly.
  • One file per chapter. The file tree is your outline, and reordering chapters is renaming files.
  • It is fast and it is quiet. No sync spinner, no toolbar, and it works on a plane.

Making it feel like a writing app

Out of the box it is set up for code, which is the wrong shape for prose — full-width lines, no wrapping, a cursor that jumps by word boundaries you did not intend. Four settings fix most of it. Put them in a workspace .vscode/settings.json so they apply to the book and not to your other work:

{
  "[markdown]": {
    "editor.wordWrap": "bounded",
    "editor.wordWrapColumn": 80,
    "editor.lineNumbers": "off",
    "editor.quickSuggestions": false,
    "editor.renderWhitespace": "none",
    "editor.fontFamily": "Georgia, serif",
    "editor.fontSize": 16,
    "editor.lineHeight": 1.7
  },
  "files.autoSave": "afterDelay",
  "editor.minimap.enabled": false
}

Then Zen Mode (Ctrl/Cmd+K Z) for the actual writing, which hides everything but the text. Two more worth knowing: the built-in Markdown preview is Ctrl/Cmd+K V, and Ctrl/Cmd+Shift+F searches the whole folder.

Extensions, kept to the four that earn their place: a spell checker (Code Spell Checker, with a project dictionary for your invented names), a prose linter if you want one (write-good or Vale — Vale is the serious option and takes an afternoon to configure), Markdown All in One for list continuation and table formatting, and a word-count extension for the status bar.

Structuring the folder

Number the chapter files. It is the whole trick, and it is what makes the folder sort into reading order and concatenate correctly:

book/
  manuscript/
    00-front-matter.md
    01-the-problem-with-mornings.md
    02-subtraction.md
    03-what-to-keep.md
    99-back-matter.md
  images/
  notes/
    characters.md
    timeline.md
  .gitignore

Leave gaps in the numbering if you like inserting chapters, or use 010, 020, 030 so you never have to renumber. The notes/ folder stays out of the book but inside the repository, which is one of the quieter benefits of this setup: research and manuscript are versioned together.

One convention worth adopting from the start: one sentence per line. It looks strange for about an hour and then it is obviously right — Git diffs become sentence-level instead of paragraph-level, and moving a sentence is moving a line. Markdown joins consecutive lines into a paragraph, so the output is unaffected. (Unless you are writing verse, where you want the opposite; line breaks in Markdown covers that case.)

Git, without the ceremony

You need about five commands, and none of the branching model arguments apply to a book with one author:

git init
git add -A && git commit -m "Chapter 3 draft"
git log --oneline              # every draft, in order
git diff                       # what changed since the last commit
git checkout -- chapter-03.md  # undo today entirely

Commit at the end of each writing session with a message describing the session. A year in, git log is a writing diary you did not have to keep. Push to a private repository and you have an offsite backup with full history, which is more than any word processor's autosave gives you.

Where the editor stops

At the point where you need a book rather than a manuscript. VS Code's Markdown preview is a web page in a panel — it is styled for reading code documentation, it has no page size, no margins, no page numbers, and printing it gives you exactly what printing a web page gives you. That is not a shortcoming; it was never trying to typeset anything.

So the last step happens elsewhere, and there are two routes. If you enjoy toolchains, Pandoc plus a LaTeX engine will typeset the folder from the command line and you can wire it to a VS Code task. If you would rather choose typefaces by looking at them, combine the chapters into one file and design it in something built for pages:

# Numbered files concatenate in reading order
cat manuscript/*.md > book.md

That single file is the handoff. Combining Markdown files goes into the details worth getting right — heading levels, image paths, the blank line between files. From there bukpress takes it: typefaces, margins, paper and covers set once, a hard page break on a line of ---, and the same file exporting both a PDF and an EPUB.

The division holds up well in practice. The editor is where the words happen and where the history lives; the production step is a separate thing you do at the end, and neither tool has to pretend to be the other. The sample book is what the second half looks like — eight pages from one Markdown file, exported once.

Read next

Tools · 6 min read

Obsidian to PDF: getting a book out of your vault

Obsidian's Export to PDF prints the note the way your current theme draws it on screen, which is why the result looks like a screenshot of an app rather than a book. To get a real book you have to decide first whether you are exporting one note or assembling a manuscript — they are different problems with different fixes.

Read it
How-to · 4 min read

How to combine Markdown files into one book

Keep chapters as separate files while you write, named so they sort in book order, then concatenate them into one manuscript with a page-break marker between each file. Do this as a last step, not as a working habit — the combined file is what you typeset; the per-chapter files stay the thing you edit.

Read it
Tools · 4 min read

Pandoc for books: what it is superb at, and where it stops

Pandoc is the best tool available for documents with citations, cross-references or mathematics, and for any book whose production is automated by a build. It stops being the pragmatic choice when your requirements are visual rather than structural, because every visual change is made by writing LaTeX or a template.

Read it

Write it in Markdown. Ship a book.

bukpress turns the file you are already writing into a typeset PDF and EPUB — your type, your covers, no watermark on any plan.

Start free — no card required