Home

Awesome

Neomux - control Neovim from shells running inside Neovim.

Neomux packages and wraps neovim-remote goodness into your neovim terminals so you can work with neovim's :term emulator in some interesting new ways. Here's some of the things it lets you do:

<p align="center"> <img width="75%" src="https://nikvdp.com/images/neomux-2-window-numbers.gif"> </p>

Quickstart

Install neomux, start a neomux shell with :Neomux (mapped to <Leader>sh by default), and use vw <win_num> <file> and friends to open files in vim windows from the shell.

For more info see the tutorial.

Installation

  1. Install neovim.
  2. Install this plugin into neovim via your favorite plugin manager (vim-plug is a good place to start)
  3. (Optional, for speed) install neovim-remote.

Usage

Neomux is meant to replace tools like tmux -- instead of relying on tmux or a fancy tabbed terminal emulator to run multiple shell windows (many of which, if you're anything like me, have instances of nvim running inside of them) you can instead just have one neovim session open and run your shells inside neovim. Vim has great tab and window splitting support, so you can rely on (neo)vim's mature window and tab management workflow to make flipping between the files you're editing and your shell(s) painless. Files and shells are both first-class citizens, and all the tools you need to pass data between neovim and your shell are included.

Basics

You can start a neomux shell in a neovim window with :Neomux or with the mapping <Leader>sh.

Terminals started via other methods (e.g. :term) will not have neomux functionality!

NOTE:

Neomux will automatically tell the shell to use your current neovim session as the default editor via the $EDITOR shell variable. This means that tools like git and kubectl will open files in your existing neovim session. Make sure you use neovim's :bd (buffer delete) command when you are finished editing your files to notify the calling program you are done -- this is equivalent to closing a non-neomux editor.

Window navigation

After installing neovim you will notice that every window in vim now shows a numeric identifier in it's status bar that looks like this:

∥ W:1 ∥

This number identifies every window on the screen and is how you refer to individual windows in neomux.

Key bindings

Neomux adds some new key mappings to make working with windows easier. The default keybindings can be customized from your vimrc / init.vim, see customization for more info.

In the default settings some commands are accessed via the <Leader> key (\ on a vanilla neovim install):

Tutorial

An extended version of this tutorial is available in the introducing neomux blog post. All neomux terminals come pre-loaded with some handy new shell commands.

Opening files in new windows: s, vs, and (kind of) t

<p align="center"> <img width="75%" src="https://nikvdp.com/images/neomux-1-new-windows.gif"> </p>

The simplest of the new neomux shell commands are s, vs and t. These stand for split, vertical-split, and tab, 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

<p align="center"> <img width="75%" src="https://nikvdp.com/images/neomux-2-window-numbers.gif"> </p> <!-- <div style="text-align: center;"> <script id="asciicast-251096" src="https://asciinema.org/a/251096.js" async></script> </div> -->

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

<p align="center"> <img width="75%" src="https://nikvdp.com/images/neomux-3-registers.gif"> </p>

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 roundabout way to replace pbpaste / xsel by using vp + (although this is silly since at the end of the day neovim will probably call those same tools to retrieve the clipboard).

CLI helper reference

When you start a neomux shell some new helper commands will be available to you to streamline working with neovim.

<!-- # Cookbook - A useful pattern is to combine `vw`, `vp`, and `xargs` to do operations over sets of files. For example, if you wanted to delete all files in a folder except for file `b`, you could do: ``` bash ls | vw 2 - ...edit the file list in nvim and delete `b`... ...select all files and yank to the `@"` register with `ggVGy`... vp | xargs rm # ``` -->

Customization

Neomux comes with a sane set of defaults, but it's meant to get out of your way, so much of it's behavior is configurable.

Configure neomux by setting any of these variables in your .vimrc / init.vim:

Key bindings:

Other config

Miscellanea / troubleshooting