Nvim-Tmux: Tools for Tmux scripting and configuration
Tmux, the popular terminal window manager, uses a quirky DSL for its configuration files. The language doesn’t really have a name – I guess it’s just “Tmux” – and it conveniently mirrors the way commands are issued as arguments to the Tmux executable, i.e. the statement set-option -ga status-style fg=#c0caf5
is interpreted as if you’d entered tmux set-option -ga status-style fg=#c0caf5
into an active shell. It does include a couple extra tricks, though, such as the ability to conditionally execute quoted commands in the parent shell, wrapped in a pretty ugly if-shell
statement. And it gets worse if you want to spill those commands onto multiple lines.
All of this is to say that there’s some room for editor plugins to make Tmux scripting easier. Along these lines, I’ve been working on Nvim-Tmux, a Neovim-native Lua port/fork of Vim-Tmux. While most Tmux-related Neovim plugins focus on connecting the editor to the multiplexer - integrating window operations, using Tmux’s command mode, etc. - Nvim-Tmux provides some tooling to assist in writing configurations and scripting in the Tmux “language”, such as it is. Some of it is basic: providing commands to continually re-source a conf
file, for example, for live editing and feedback. Others are more aspirational: Nvim-Tmux lets you quickly pull up documentation for a command in a floating window with a single command, and I’m hoping to extend this to LSP hover-like functionality as well.
One thing I’m excited about is some future Treesitter integration. While the Tmux DSL is probably simple enough for regex-based syntax highlighting to do the job (this isn’t always the case with other langagues), Treesitter is particularly adept at identifying subcomponents of a source file that should employ a different language’s syntax highlighting rules, e.g. when HTML is embedded within JSX/TSX files. If I can wrangle up a Tmux Treesitter parser, then bash/zsh highlighting can be applied to quoted shell commands, instead of treating them like a big homogenous quote block.
Nvim-Tmux is written entirely in Lua, with only one or two calls to vanilla Vim commands. This has been quite a learning experience! It’s very funny to search for a simple problem (say, string interpollation) in Lua and finding hits from World of Warcraft fan wikis among the top results. The extreme dynamic typing feels a little wobbly, and the challenge of printing tables in the native REPL is annoying, but I love that the community feels genuinely human-scale (a core tool like Stylua is written by a college student and only has 600 stars on GitHub), and the insanely minimal regex-like implementation grows on you once you understand its motivation.
I don’t know if I’ll ever find professional benefit from picking up a language that appears to be used chiefly by 15 year olds trying to make Minecraft mods, but I appreciate that Neovim chose something outside the somewhat weary circle of Python/JS scripting that dominates so many other editors.