DEV Community

Rajasegar Chandran
Rajasegar Chandran

Posted on • Edited on

Helix, tmux and lazygit

In this post, we are going to see how to use lazygit with Helix to manage your git repositories.

In the past, with Neovim which I have been using for a very long time, I relied on git plugins like vim-fugitive which does not cover all my use cases exhaustively but it just gets the job done.

Having used Magit in Emacs, I couldn't find any solid replacement plugin for my git workflow. Nothing comes close to Magit actually. But recently I heard about lazygit which is quite awesome once I stared using it.

Helix

Helix is a postmodern text editor built in Rust built for the terminal. It has got multiple selections, built-in Tree-sitter integration, powerful code manipulation and Language server support.

One of the best thing about Helix is the no-plugin philosophy. You might not need any plugins, because you already have all the features built in like Fuzzy finder to jump to files and symbols, project wide search, beautiful themes, auto closing bracket pairs, surround integration and more. All you need is to just enable and tweak them in the config file.

Lazygit

Lazygit is a simple terminal UI for git commands, written in Go with the gocui library.

Tmux

tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal.

My workflow

I have an IDE setup with tmuxinator where I pre-configure different window and pane layouts. You can check out my dotfiles here.

This is how I want to use lazygit with Helix and tmux.

  • From Helix, I need to open lazygit in a separate tmux pane
  • Work with git repository in the new tmux pane using lazygit and return back to Helix

From the requirements above, it looks like we need a key binding to automate all these tasks within Helix. So let's get started.

Helix has got this command :sh to run any shell commands from Helix. Using the same, we are going to invoke some tmux commands.

First we assume that ,there is already an empty pane open next to our editor pane. We are going to open lazygit in that pane using the command:



tmux send-keys -t 2 lazygit Enter


Enter fullscreen mode Exit fullscreen mode

Here 2 is the id of the second pane.

Next we are going to move our focus to the pane.



tmux select-pane -t 2


Enter fullscreen mode Exit fullscreen mode

When we wrap all the above commands into a key binding in our Helix config.toml using the keys Ctrl + g, it will look something like this:

Key mapping



[keys.normal]
C-g = ":sh tmux send-keys -t 2 lazygit Enter && tmux select-pane -t 2"


Enter fullscreen mode Exit fullscreen mode

Image description

Update

I have updated my key mapping to make use of tmux popup instead of opening or choosing a tmux pane and run lazygit there. This new workflow is super awesome and very accessible.



[keys.normal]
C-g = ":sh tmux popup -d \"#{pane_current_path}\" -xC -yC -w80% -h80% -E lazygit"


Enter fullscreen mode Exit fullscreen mode

Here we are opening a floating window using tmux popup command and passing the current directory using the -d flag with "#{pane_current_path}" as the value. We are also customizing the popup size by making its width and height 80% using the width, height, x and y parameters.

Image description

A Big Thanks to kenos from the Helix Matrix community for suggesting tmux popup

Hope you enjoyed the post. Please let me know for any improvements in the workflow. If you think there is a better tool than lazygit, also let me know how you are using in the comments section below.

Top comments (2)

Collapse
 
dexter2305 profile image
Naveen

Nice write up. Got a similar setup but with zellij to execute long running tasks (build/test) in a pop up terminal shell.

Collapse
 
richcorbs profile image
richcorbs

How would you trigger a "reload all" after returning from lazygit where you've changed branches? When I tried the reload ran before lazygit returned.