Since this is my first post, I decided to include it before it's completed for testing purposes. However, I believe the article already contains enough information to get anyone started with the Helix editor.
If you've written any kind of code, you've probably used an Integrated Development Environment (IDE), a Code Editor, a modal text editor or a normal text editor.
The article is mainly focused on a modal text editor, Helix. However, to get there we have to understand IDEs, Code editors and then finally dive deep into helix editor.
Integrated Development Environment
According to Wikipedia;
An integrated development environment (IDE) is software that provides a relatively comprehensive set of features for software development. At a minimum, an IDE typically supports source-code editing, source control, build automation, and debugging.
However, the same can be achieved in code editors and also the modal text editors discussed later on. The difference is that for an IDE, everything comes as one package. You install one program and get all the good stuff with minimal additional setup. Let's take Pycharm for example, a popular Python IDE from Jetbrains, by default you get so many features such as git integration, debugging, an interpreter and support for library integrations such as Django. I think it even has Jupyter Notebook support.
There's an IDE for all mainstream languages out there. Check out Awesome-IDEs
Code Editors
The most common text editor, by far is VS Code. Code editors are designed specifically for code editing and provide features for achieving that. They come with syntax highlighting by default and shortcuts for easily manipulating code.
What differentiates IDEs and Code editors is that, code editors are not really specialized on one programming language. You can setup your code editor to work with Python, Rust or C. For that reason, to achieve functionality such as code actions, you have to manually install plugins. These plugins provide Language Server Protocols. The plugins are not however just focused on Language support, there are plugins for so many things, including themes.
Code editors are mostly a little more lightweight than IDEs. It is still possible to bloat your code editor to the point that it's heavier than the IDEs themselves.
Text Editors
Code editors are convenient since they offer the perfect balance of control and simplicity.
Some text editors are very simple and are only useful for making slight changes to files. GNU Nano is one classic example. It does provide syntax highlighting and a few shortcuts to perform quick actions.
There are other text editors that provide a way to extend their functionality.Vim, Neovim,Emacs and Helix are all examples of these kind of text editors.Emacs is too extensible to even be called a text editor, while Helix currently doesn't support plugins like Vim and Neovim (There are however plans to include one).
Modal Text Editors
A modal text editor has multiple modes of operation and the key's function change depending on which mode it is in. Helix is highly inspired by other modal text editors - Kakoune and Neovim.Kakoune was also inspired by Vim and as you might have already deciphered, Neovim is the "Neo" Vim :).
The key thing to note here is that there is a deep-seated relationship between these editors. However, you do not need to be familiar with the aforementioned editors to learn Helix. ( A familiarity with any of them will obviously make it easier to learn the other due to their overlapping functionality).
One of the most popular modal text editors is Vim/ Neovim. With vim you can add plugins and configure it using Vimscript. Even though vim is still actively maintained, most people have migrated to Neovim.The difference is that Neovim introduced Lua as the preferred language for writing plugins.
Neovim is quite bare bones to begin with. To achieve most of the tasks you have to set-up a file explorer, language server, themes, fuzzy search and so much more. This means that for any new functionality you need, you will have to edit a lua file. If you love tinkering, and building your own editor from scratch, then Neovim might be for you.
There are also some Neovim distros such as LazyVim and NvChad. I have tried both of them and they are pretty solid and give you almost a complete setup for most of the basic stuff you will need. They have by default a package manager (lazy.nvim), allowing you to quickly install other plugins and extend your Neovim configuration as needed.
The baseline here is, to get a good working environment in Neovim, you will have to do some tinkering. That's where helix comes in. Unlike Neovim, helix has most of the necessary features built-in. It has a fuzzy search, LSP support and themes all built-in. No setup required, and your editor just works. Now, don't get me wrong, you still might have to touch the config files to change a few things such as themes and the behaviour of LSPs but not quite as frequent as you have to in Neovim.
Helix uses TOML for configuration which is quite simple.
Helix Features
Helix has so many features which will be discovered as you continue learning more about it. Some of the key features include:
-
Built-in Language Server Support
-
Multiple Selections
-
Smart Incremental syntax-highlighting
Installing Helix
Explaining all possible ways to install helix is impractical. See the official installation instructions from the official helix website.For example, to install it on arch linux:
sudo pacman -S helix
After installing helix, I believe that the tutor is enough to get anyone up and running with helix.
To access the tutor, run the following command
hx --tutor
If you are on archlinux, you may have to use the full name:
helix --tutor
If you want to use the command hx, either create an alias or just create a symlink to the helix binary on a file named hx.
sudo ln -s /usr/bin/helix /usr/local/bin/hx
# /usr/local/bin/ should be in $PATH
I am going to include the basics needed to get up and running with helix in this article. We may end up covering everything in the tutor and more.
If you are already familiar with vim, you can skip most of these introductory sections. There are however some subtle differences. I cannot document all of them here, since this is not a guide about migrating from Neovim or Vim. One key difference I can note is that in vim, the command comes before the selection such as dw to delete a word, while in Helix you would use wd. This gives some form of visual feedback on the text your are about to perform changes on. If you are already familiar with modal text editing, you may want to skip to Configuring helix
Helix Basics
This section covers the basics of modal text editing including movements and commands.
Modes
Helix has three main modes:
-
Normal mode: This the default mode and it is used for navigation and editing commands.
-
Insert mode: This mode is used for typing text into the document. One way to enter insert mode from normal mode is pressing
i -
Select/ Extend mode: Used for making selections and performing operations on them. Accessed by typing
vwhile in normal mode.
Basic Cursor Movement
The keys h, j, k and l are used for basic movement. The arrow keys can also work but it is recommended to use these keys as there are some useful combinations with these keys. Also, it helps in keeping your fingers in the home row.
- h - Left
- j - Down
- k - Up
- l - Right
Exiting Helix
I can't quit Helix
— VS code user
Not being able to quit Vim has been quite the long running joke. The post-modern version: "I can't quit
helix!". Anyway, to quit helix, you need to be in Normal mode or in Select Mode( Press Esc to enter normal mode). Then press : to enter command mode then q short for quit to quit. If you had unsaved changes the command :q will fail, use :q! to force quit.
Deletion
To delete text use the d key. Pressing the d key in normal mode without any selection deletes the character under
the cursor. It can also be used in combination with selections to delete chunks of text (To be demonstrated later). For now, just remember that d deletes text.
Insert Mode
There are several ways to enter insert mode. The most common is i , used to enter insert mode before the selection.
-
a- Insert after the selection (append) -
I- Insert at the start of a line -
A- Insert at the end of the line
Opening Lines
o- add a newline and insert below the cursor.O- add a newline and insert above the cursor
Saving a File
To save/ write to a file use :w' or :write. You can also use :wqor:write-quit` to write and quit.
It should already be obvious that typing : while in normal mode takes you to command mode. I might not include : for subsequent commands.
You can also save to a specific file by using :w /path/to/file
The path can be either relative to the directory in which helix is opened in or an absolute path.
Motions and Selections
Motions are used to move around and to make selections. For example, w can be used to move forward a word. This also automatically selects the word and actions can be performed on the word. Hitting w again will move forward to the next word, selecting it. The motions can be combined with commands such as d to delete a word. For example, using dw will delete the word.
When in select mode, w can also be used to select a word. The difference is that hitting w again while in select
mode will add the next word to the selection.
Common Motions
w- Move forward to before the beginning of the next word.e- Move forward to the end of the current word.b- Move backward to the beginning of the current word.
WORDS and words
The w, e, b motions have counterparts W, E and B. The uppercase counterparts traverse WORDS instead of words. WORDS are separated by whitespace only, while words can be separated by other characters. For example: info@mwendwakavete.co.ke contains 7 words (info, @, mwendwakavete, . , co, . and ke but only one
WORD (info@mwendwakavete.co.ke).
Counts with Motions.
All the motions can be combined with numbers to perform that motion the specified number of times. [number] [motion] performs motion number times. Example: To move 5 WORDS forward, 5W (5 + Shift + w).
The Change Command
c is used to change the current selection. It deletes the current selection and enters insert mode. It's a short form
of di.
Select/Extend Mode
To enter select mode, type v. To exit select mode, type v again or Esc. In select mode, every movement extends the current selection instead of replacing it. In Normal mode, hitting w selects the current word and hitting w will move to the next word and select it. In select mode, the same motion will select 2 words. Performing commands on selected text returns you to normal mode.
Selecting Lines
To select the current line, type x while in Normal or Select mode. To select the next line type x again and so on. You can also combine with numbers to select a specified number of lines. For example, 5x selects 5 lines down starting with the current one. x does not select empty lines. X also selects the current line in a similar manner to x, except that it doesn't extend to subsequent lines.
Collapsing Selections
If you would like to deselect without moving the cursor, use ;
Undoing
u- undoU- redo
Copying and Pasting Text
To copy/ yank the current selection, use y and then use p to paste the yanked text after the cursor. To past it before the cursor, use P. It is important to note that helix doesn't share the system clipboard by default. To yank to the system clipboard, use Space+y and to paste from the system clipboard, use Space+p. Make sure you have a clipboard manager installed. This will most likely be already installed on your system if you are not working with minimal installations of archlinux, void-linux or some other distro. Since I am on wayland, I had to install wl-clipboard.
Note: Anytime you delete or change text, helix will copy the deleted or changed text.
sudo pacman -S wl-clipboard
Searching in a File
To search forward in a file, type /, then type n to go to the next search match and N to go to the previous. To search backward, use Shift+/
Now that we can do some basic stuff with helix, it is time to see how we can configure various aspects of the editor such as setting a theme.
Configuring Helix
Helix is configured via a config.toml file. The location on Unix based systems is ~/.config/helix/config.toml. On windows, the directory looks something like %AppData%\helix\config.toml. You can also just open the config right from helix without traversing directories manually by running the command :config-open within helix normal mode.
Look at this minimal config file:
theme = "github_dark"
[editor]
line-number = "relative"
soft-wrap.enable = true
mouse = false
[editor.cursor-shape]
insert = "block"
normal = "bar"
select = "underline"
You can easily figure out what each of those settings change. As mentioned before, helix uses TOML (Tom's Obvious Minimal Language) for configuration which is quite easy to grasp. This simple config sets guthub_dark as the preferred theme for the editor, sets up relative line numbers and enables soft wrap. It also sets up cursor shape in the different modes. Helix allows you to customize many parts of the editor, includig the statusline, the file picker among others. Check out the editor section configuration options from the official docs for a complete guide. Make sure to play around with the different settings and observe the changes.
Themes
Helix comes with over 100 themes by default. You can check them out by typing the command :theme a list of the themes will popup, somewhere on the bottom left. You can then tab over the themes to try them out temporarily. If you like a theme, you can then add it to your config by adding theme = "yourtheme" at the top level of your config.
You can also create your own themes. This can also be done by inheriting from the existing themes and tweaking specific parts to achieve your desired theme. For example, I used this feature to force helix to inherit the background opacity of my terminal (I love glazing at my wallpaper when working from the terminal 🙂).
To achieve that, create a folder named themes on the same level as the config.toml file. On unix based systems, this would be ~/.config/helix/themes and on Windows, this would be %AppData%\helix\themes. You can then create a theme in the folder, in my case I create a theme named transparent.toml, and add the following.
# My theme inherits the inbuilt bogster theme
inherits = "bogster"
# Set various sections' bg to none
# For example "ui.menu" configures the code and command completion menus
"ui.background" = { bg = "none" }
"ui.window" = { bg = "none" }
"ui.statusline" = { bg = "none" }
"ui.help" = { bg = "none" }
"ui.menu" = { bg = "none" }
"ui.popup" = { bg = "none" }
Language Server Protocol Support
Helix has language server support provided out of the box. Just install your LSP and helix will pick it up. For example for C language support, I installed clangd, and helix automatically provides code actions such as code completions and definitions. You can configure the language options in a languages.toml file located in the same location as the config.toml file, which overrides the default configuration provided by helix. You can also have configuration files local to a project by creating a .helix directory in the project root and then create a languages.toml there.For example, to enable both ruff and pyright support for the Python programming language, add the following in languages.toml
[[language]]
name = "python"
language-servers = [ "pyright", "ruff" ]
To install the Language servers, in archlinux I used:
sudo pacman -Syu pyright ruff clang
Please note that these might be different based on your Operating system. Make sure to find out how to install the LSPs for your system. Just install the LSP and it will work out of the box. The configuration is only needed to control the behaviour of the LSPs.
To check if the LSP is detected, you can run hx --health language. For example, check status for Python, hx --health python. With our current setup, the output would be something akin to:
Configured language servers:
✓ pyright: /usr/bin/pyright-langserver
✓ ruff: /usr/bin/ruff
Configured debug adapter: None
Configured formatter: None
Tree-sitter parser: ✓
Highlight queries: ✓
Textobject queries: ✓
Indent queries: ✓
Check out Language Configuration for more information.
More Helix Features
Multiple Cursors
If you would like to make the same change on multiple lines, you can use C to duplicate the cursor to the next suitable line. To remove the cursors except the last one, type ,. To duplicate the cursors upwards instead of downwards, use Alt+C
The Select Command
The select command is quite useful when you want to perform some kind of search on a specified chunk of text.Think of it as performing some kind of "grep" on the text. For example, let's say you would like to change all occurrences of a variable in a line. Select the line, x and then type s for select mode. A prompt will appear on the status line prompting you to enter the search term. Entering the term will select all occurrences of the term and actions performed will affect all the selections.
The selections don't have to be exact matches! You can also use regular expressions in place of the search term and all the text matching the specified expression will be selected.
Find and Till Motions
Find Motion(f<ch>): Select up to and including a character.
Till Motion(t<ch>): Select up to but not including a character.
To do the same but backward use F and T for find and till.
The Replace Command
Use r<ch> to replace all selected characters with r-, the five spaces will be replaced by -.
Typing R replaces the selction with previously yanked text.
Joining and Identing Lines
To join lines together type J.
To indent a line, type >, and < to unindent it. This also works on selections and with multiple cursors.