Introduction

Helix is not only the perfect code editor but also ideal for writing documentation. By combining the advantages of modal editing with many built-in features, Helix makes creating documentation and prose a fantastic experience.

Since most documentation is written in Markdown, this tutorial focuses on Helix’s Markdown capabilities. It explores key features, suggests additional configurations, and recommends third-party language servers. This tutorial is specifically designed for Helix version 25.01.1.

Using Soft Wrap

Soft wrapping allows your documents to automatically adapt to your editing window or a specified line length without imposing permanent hard formatting. This feature simplifies document editing.

When text wraps, a wrap indicator symbol appears at the beginning of the new line:

Default Wrapping Indicator

You can easily change or remove the wrap indicator symbol. In this example, remove it entirely:

config.toml

[editor.soft-wrap]
wrap-indicator = ""

Customized Wrapping Indicator

By default, soft wrap is disabled. You can enable it in the following contexts:

  1. Globally in the config.toml file:
[editor.soft-wrap]
enable = true
  1. Per project in the .helix directory’s config.toml file:
[editor.soft-wrap]
enable = true
  1. Per language in the user’s languages.toml file:
[[language]]
name = "markdown"
soft-wrap.enable = true

Enabling soft wrap adjusts the text to fit the width of your window, which is particularly useful in smaller window sizes, such as when using vertically split views. If you prefer a more readable format in a full-screen window, wrap at a hardcoded value using wrap-at-text-width instead of relying on the window size:

languages.toml

[[language]]
name = "markdown"
soft-wrap.enable = true
# text-width = 80 < this is the default
soft-wrap.wrap-at-text-width = true

Toggling Soft Wrap

Add the following configuration to toggle soft wrap on and off:

config.toml

[keys.normal.space.t]
s = ":toggle soft-wrap.enable"

Soft Wrap vs :reflow

:reflow is Helix’s version of hard wrap and makes permanent changes to your formatting. The line length can be set with text-width in your config.

A full list of configuration options is available in the documentation.

To quickly create links, such as image links:

  1. In insert mode, type ! to start creating an image link.
  2. Type [ to automatically create a pair using automatic pair completion, then type the image link text inside it.
  3. Press Tab to skip over the closing ] using the smart tab feature.
  4. Create another pair of brackets with (.
  5. Use path completion by typing ./ to find files in the current directory and select the desired image file.

To quickly select text within links, use match mode with the command mim (match inside closest surrounding pair):

  1. In normal mode, place the cursor inside the [] or () pairs.
  2. Type mim.
  3. Proceed with operations like c to change or y to yank.

Match Mode Example

To open a link in your browser, place the cursor over the URL and type gf.

Using the Marksman Language Server

Marksman Splash

Marksman is a general-purpose language server for Markdown and is the default in Helix. Install it, and it will work out of the box.

Marksman helps you quickly find and jump to specific headings or anchor tags in a document.

  1. Open the Symbol Picker: Press Space s. Marksman symbol picker

  2. View Headings and Tags: The symbol picker displays a fuzzy searchable list where:

    • Kind: Is always string.
    • Name: Consists of the heading level or tag and the title.

To navigate using goto definition on links:

  1. Place your cursor on the link: Press gd.

Choosing a Spelling/Grammar Checking Language Server

There are three main choices for a language server for grammar and spelling. This section compares them.

Harper-ls

Harper logo

Harper is the latest and most promising language server. It is written in Rust and uses fewer resources than its competitors. It was recently acquired by Automattic, and the main developer was hired to work on it full-time, indicating a strong future.

  • ✓ Ability to save words to a dictionary using code actions
  • ✓ Faster and more resource-efficient than competitors
  • ✗ Less comprehensive grammar checking due to its newness
  • ✗ Only supports US English

Vale

Vale stands out by enforcing custom style guides for technical writing alongside spell checking, though its grammar checking is less advanced. Its newly introduced language server is still basic.

  • ✓ Wide range of style guides available, including Microsoft
  • ✗ Primitive language server support; you must constantly save to update the language server, or it becomes out of sync with the document
  • ✗ Only supports US English

Ltex-ls Plus

LTEX+ is a new fork of LTEX Language Server that uses LanguageTool under the hood. Development of ltex-ls had stalled, but with the new fork, fixes and features are being quickly merged.

LanguageTool is a mature and respected grammar and spell checker. It offers the most advanced grammar checking and can be used with n-gram data for enhanced capabilities. However, it is slow and memory-intensive. It may take time to initially check even a small document, but performance improves significantly afterward.

  • ✓ Superior grammar and spell checking
  • ✓ Supports many natural languages
  • ✓ Highly configurable
  • ✗ Currently unable to save words to a dictionary using code actions
  • ✗ Resource-intensive and slow

Comparison of Language Servers

Feature Harper-ls Vale LTeX+
Multi-language Support ❌ ❌ ✅
Custom Dictionaries ✅ ✅ ⚠️ Manual
Real-time Feedback ✅ ❌ ✅
Resource Usage Low Low High

Configuring ltex-ls-plus

ltex-ls-plus is the recommended choice. Support is built into Helix, so install it into your PATH and add it to languages in your languages.toml file. Helix uses Marksman as the default Markdown language server. You can also add ltex-ls-plus, as Helix allows multiple language servers to run simultaneously:

[[language]]
name = "markdown"
language-servers = ["marksman", "ltex-ls-plus"]

ltex-ls-plus Custom Settings

You can add custom settings. The following configuration sets the default diagnostic severity level to warning, sets the log level to warning to prevent excessive logging in Helix, disables profanity rules, and adds the word builtin to the dictionaries for US and GB English.

[language-server.ltex-ls-plus.config]
ltex.diagnosticSeverity = "warning"
ltex.ltex-ls.logLevel = "warning"
ltex.disabledRules = { "en-US" = ["PROFANITY"], "en-GB" = ["PROFANITY"] }
ltex.dictionary = { "en-US" = ["builtin"], "en-GB" = ["builtin"] }

While adding to the dictionary in the config is less convenient than using a code action, from version 18.6.1 you can also add to the dictionary per document using magic comments. For example:

<!-- LTeX: dictionary+=word1 dictionary+=word2 dictionary+=word3 -->

Setting the Language per Document in ltex-ls-plus

Use YAML front matter at the top of your Markdown document to specify the language. For example, to use British English:

---
lang: en-GB
---

Using the default US English (en-US) will result in unwanted errors if you try to use British English:

British English Example

Using Prettier to Format Your Markdown

For Markdown formatting, Prettier is highly recommended. While faster formatters exist, Prettier uniquely supports formatting across multiple languages within code blocks.

The following settings instruct Helix to automatically format Markdown using Prettier when the document is saved. Alternatively, you can omit the auto-format setting and use the :format command manually.

languages.toml

[[language]]
name = "markdown"
formatter = { command = 'prettier', args = [
  "--parser",
  "markdown",
  "--prose-wrap",
  "never", # <always|never|preserve>
] }
auto-format = true

Markdown Preview in the Browser

There are many ways to preview Markdown files in a browser. Terminal-based tools like glow exist, but they do not display images, limiting their usefulness. If you are using a framework like Hugo or mdBook, built-in live preview commands such as hugo serve or mdbook serve are available.

If no live preview is available, consider the following solutions:

Previewing with Pandoc

If automatic preview updates on saving are not required, a simple key binding using Pandoc works well on Linux and macOS:

config.toml

[keys.normal]
"F6" = "@:sh pandoc --resource-path <C-r>%<C-w> --self-contained --metadata title='Preview' <C-r>% -o /tmp/md-preview.html && xdg-open /tmp/md-preview.html<ret>"

This keybinding uses Pandoc to convert the current file into fully styled HTML with syntax-highlighted code blocks. It assumes a Markdown file is in the current buffer and saves the HTML output to /tmp/md-preview.html. The --resource-path flag ensures images load correctly by specifying the document’s directory. The resulting HTML opens in your system’s default browser.

Previewing with the markdown-preview GitHub CLI Plugin

A good option for live previews with automatic updating is gh markdown-preview. It requires GitHub CLI as a dependency.

To preview your file, run gh markdown-preview <filename>. The document opens in your browser using GitHub’s styling. Saving the file triggers an automatic preview update. Alternatively, configure Helix to automatically save after a period of inactivity.

Previewing with Markdown Preview Language Server

Markdown Preview Language Server enables browser-based Markdown previews and integrates with Helix. It can be configured using the provided settings and downloaded from the GitHub releases page, serving as a maintained replacement for the unmaintained mdpls.

Creating a Zen Mode

Zen mode, inspired by VS Code Zen mode, minimizes distractions by hiding non-essential UI elements, helping users focus on their work.

Giant Buddha statue

A key feature is centering the document on screen to reduce neck strain from side-to-side eye movement.

A pull request for zoom and max-width support aims to provide native centering. Until then, use the following workaround to center the editing area.

Increase the minimum width of line numbers to push the content toward the center. A line length of 80 characters is ideal for readability, with 100 as a reasonable maximum. See this article on line lengths for more details. The following setting works well on a 4K display:

[keys.normal.space.t]
z = ":toggle gutters.line-numbers.min-width 52 3"

Adjust the value 52 based on your monitor and terminal size. On Linux and macOS, run stty size in a fullscreen terminal to get the dimensions. For example:

$ stty size
48 192

If your terminal width is 192 characters, and you want to create a space of 80 characters in the middle, you need to calculate the spaces on each side.

# Subtract desired width from total width
192 - 80 = 112

# Divide by 2 to get space per side
112 / 2 = 56

# Subtract 4 for line numbers and git gutter
56 - 4 = 52

This results in 52 extra characters of padding on the left, centering the 80-character content area.

Helix zen mode hack

In a bash one-liner that would be:

stty size | awk '{print (($2-80)/2)-4}'

and a Helix shortcut:

z   = ":toggle gutters.line-numbers.min-width %sh{v=$(stty size < /dev/tty | awk '{print (($2-80)/2)-4}'); [ $v -gt 2 ] && echo $v || echo 3} 3"

This is a little more complex, we need to use stty size < /dev/tty as stty size silently fails inside a background shell. We also need to default to 3 if the result is not valid, which will happen if the width of the terminal is too small.

Conclusion

This tutorial has provided a comprehensive guide to using Helix for Markdown documentation. We covered essential features such as:

  • Enabling soft wrap
  • Creating and editing links
  • Using the Marksman language server for enhanced navigation
  • Grammar and spell checking with various language servers
  • Formatting and previewing Markdown documents

By applying the configurations and practices outlined, users can significantly improve their documentation workflow in Helix, making it more efficient and organized.