Neovim switch / foo.mli edit=

Is there a way, where

  1. when editing foo/, we can switch to foo/bar.mli
  2. when editing foo/bar.mli, we can switch to foo/

Basically I want to swap .ml ↔ .mli for the buffer/file I am editing.

You can use the :r expand modifier to remove the extension from the filename and type the one you want:
From the .ml file :e or from .mil :e