Neomux, or why you don't need tmux
Introducing Neomux
As a long-time vim user, one of the things I’ve always been background level jealous of is the claim, sometimes made by our long-lost emacs brethren, that emacs is an operating system and vim is just a text editor. There’s some truth to that, until recently vim was much less extensible than emacs. Neovim’s arrival on the scene has changed things however.
Neovim added a bunch of new and useful features to vim, but one that’s been a bit under-rated is the terminal emulator. This lets you run a shell directly inside a vim window, which is something that I never knew I always wanted.
Unfortunately, using nvim as a tmux replacement doesn’t work very well in the
default configuration. The default keybinding (<C-\><C-n>
) to exit terminal
mode is clunky, and worse, the shell isn’t well integrated with neovim, so most
people end up going back to tmux.
Neomux aims to fix that. It does so by setting up some (imo) sane keymaps and default behavior, and more interestingly, by setting up some helper functions to make neovim and the terminal play together nicely. The key idea behind neomux is that it should be easy to manipulate your vim files and buffers from the shell, and vice versa. This plugin is mostly a wrapper around the excellent neovim-remote, and allows you to do cool things like pipe a command into a vim window.
Tutorial
All Neomux terminals come pre-loaded with some handy new shell scripts.
Opening files in new windows: s
, vs
, and (kind of) t
The simplest of the new neomux shell commands are s
, vs
and t
. These
stand for s
plit, v
ertical-s
plit, and t
ab, and are straightforward to use.
If you have a neomux shell open and wanted to open a file you were looking at in a new window, you would simply do:
s <some-file>
Similarly, vs <some-file>
, and t <some-file>
would open <some-file>
in
a vertical split, or a new tab, respectively.
Working with windows by window-number: vw
and vwp
One of the most commonly used neomux commands is vw
(vim-window), it allows
you to open a file in an already open window.
For example if you have 3 windows open in your current nvim session/tab and you
wanted to open a file named my-file.txt
in the 2nd window you’d do:
vw 2 my-file.txt
You can also use pass -
as the filename to stream the contents of stdin
into a vim-window, which when combined with the shell’s |
characters makes
for some interesting possibilities.
The vwp
(vim-window-print) command does the reverse of the vw
command. It
takes the contents of any vim window and streams it out to standard out. When
you combine this with your shell’s process substition
functionality, you can do some interesting things such as interactively working
on a bash script without having to first write it to a file. Check out vid above
for more details
Copying/yanking and pasting text to and from neomux
Neomux comes with two helpers for working with vim’s registers to copy and paste
text: vc
and vp
, which stand for vim-copy and vim-paste respectively.
With these, you can manipulate the contents of vim’s yank ring and registers from the command line. If you’re not familiar with vim’s register system, I recommend first checking out vim’s documentation on the topic and/or this tutorial.
Both vc
and vp
, work on the default register (@"
) if no register is
specified. To work with a specific register just pass it as the first cmd-line
param. For example, to work with register a
(@a
), you would use vw a
, and
vp a
.
To put data in a register pipe it in via stdin:
$ echo "This is what's in register a." | vc a
And get it out with vp
:
$ vp a
This is what's in register a.
All vim register semantics are preserved, so you can append to the contents of a register by capitalizing the register name:
$ echo " Appended to register a." | vc A
$ vp a
This is what's in register a. Appended to register a.
Special registers such as /
and +
work just like any other register, so
you could even use these as a replacement for pbpaste
/ xsel
by using vp +
.
$ echo "hi from the system clipboard" | pbcopy # replace pbcopy with xsel --clipboard --input on linux
$ vp +
hi from the system clipboard