I recently discovered the text editor Helix, a relatively new project written in Rust. Many features, like Tree-sitter integration or support for the Language Server Protocol LSP are available by default without any plugins or laborious configuration. This short note shows how to integrate Helix with the template tool Tp-Note and the grammar checker LanguageTool under Linux.

Helix syntax highlighting with Tree-Sitter

Installation and configuration

Tp-Note

Download a recent version of Tp-Note and follow the Tp-Note's installation instructions.

Tp-Note needs to know how to start your favourite terminal emulator in a way that it invokes Helix at startup. Add the following lines to /etc/environment, with sudo nano /etc/environment:

TPNOTE_EDITOR="xfce4-terminal --disable-server -x hx"
TPNOTE_EDITOR_CONSOLE="hx"
TPNOTE_LANG_DETECTION="de-DE, en-GB"

The last line, configures Tp-Note's language detection feature. Here you indicate a list of languages you usually write your notes in. Alternatively, the equivalent environment variable setting can be achieved with a configuration file in ~/.config/tpnote/tpnote.toml with the following content:

[app_args]
unix.editor = [ [ "xfce4-terminal", "--disable-server", "-x", "hx" ] ]
unix.editor_console = [ [ "hx" ] ]

[[scheme]]
name = "default"
[scheme.tmpl]
filter.get_lang = ["en", "de"]
filter.map_lang = [ ["en", "en-GB"],  ["de", "de-DE"] ]

More configuration options are described on Tp-Note's manual page .

For convenience, I added some custom actions to my file manager Thunar by inserting the following <action> tags in /etc/xdg/Thunar/uca:

<action>
  <icon>accessories-text-editor</icon>
  <name>Tp-Note</name>
  <command>tpnote %f</command>
  <description>Tp-Note</description>
  <patterns>*</patterns>
  <directories/>
  <audio-files/>
  <image-files/>
  <other-files/>
  <text-files/>
  <video-files/>
</action>
<action>
  <icon>accessories-text-editor</icon>
  <name>Tp-Note View</name>
  <command>tpnote -v -n %f</command>
  <description>Tp-Note View</description>
  <patterns>*.txt; *.md;*.rst;*.adoc</patterns>
  <text-files/>
</action>

Please refer to Tp-Note's user manual for instructions how to configure other file managers or other operating systems.

LanguageTool

As LanguageTool has no direct support the Language Server Protocol LSP, we need a protocol converter. The proxy software LTeX ships with a LanguageTool standalone version and exposes the LSP protocol. Follow the installation instructions for LTeX-LS.

Helix

Helix has built-in support for the LSP protocol. Follow the installation instructions for your operating system. In order to tell Helix the path to the above LTeX-LS installation, we create the additional configuration file /home/<username>/.config/helix/languages.toml with the following content:

[[language]]
name = "markdown"
language-servers = [{ name = "ltex"}]
file-types = ["md", "txt"]
scope = "text.markdown"
roots = []

[language-server.ltex]
command = "/opt/ltex-ls/bin/ltex-ls"

[language-server.ltex.config.ltex.dictionary]
"en-US" = ["Tp-Note","Zettelkasten"]

Hereby indicates the expression command =/opt/ltex-ls/bin/ltex-ls the path to the shell script ltex-ls which is part of the LTeX-LS installation. Change this to path to the location where you unpacked LTeX-LS.

Usage

Create a new note by invoking Tp-Note (more examples here):

mkdir "Build a Crypto Currency"
cd "Build a Crypto Currency"
tpnote

Tp-Note opens the Helix editor which starts for its part the LanguageTool grammar checker. Note, that the grammar checker reads the header variable lang: indicating the language of the current note. In the below example, its value en-US is automatically determined by Tp-Note's linguistic language detection feature. If Tp-Note's suggestion does not fit, it can be overwritten in the note's YAML header.

Hover the cursor over the word “However” to see what is wrong:

A comma may be missing ...

Type [space], [a] to see the suggested corrections:

Navigate with Ctrl-n and commit your choice with Enter:

Extra

No additional plugins or any further configuration is needed so far. Everything should work out of the box.

However, for completeness you will find below my Helix configuration file ~/.config/helix/config.toml.

theme = "autumn"

[editor]
color-modes = true
auto-save = true
soft-wrap.enable = true
middle-click-paste = false
rulers = [80, 100]

[editor.lsp]
display-messages = true
display-inlay-hints = true

[editor.cursor-shape]
insert = "bar"
normal = "block"
select = "underline"

[editor.statusline]
left = ["mode", "spinner"]
center = ["file-name"]
right = ["diagnostics", "version-control", "selections", "position", "file-encoding", "file-line-ending", "file-type"]

[keys.insert]
j = { k = "normal_mode" } # Maps `jk` to exit insert mode.
C-h = "delete_char_backward" # Most terminals do this by default.
C-l = "move_char_right" # Useful to jump over a closing parenthesises.
C-s = ["save_selection", ":w"] # Add `:w` to the default binding.

[keys.normal]
Z = { Z = ":wq" } # Shortcut to save and close buffer.
C-h = "delete_char_backward" # Most terminals do this by default.
C-l = "move_char_right" # Useful to jump over a closing parenthesizes.
C-s = ["save_selection", ":w"]
C-j = "jump_backward" # C-o is sometimes captured by the "MidnightCommander"

Read more about Tp-Note

A good start is Tp-Note's project page or the introductory video. The source code is available on GitHub - getreu/tp-note and some binaries and packages for Linux, Windows and Mac can be found here. To fully profit of Tp-note, I recommend reading Tp-Note's user manual. If you like Tp-Note, you probably soon want to customize it. How to do so, is explained in Tp-Note's manual page.

Last updated: 20230520