OttyAddons
All addons

Smart Splits

Built in

Move between Otty panes and Neovim windows with the same keys. In Neovim the keys go to Neovim; at its edge it hands focus back to Otty.

What it can do

  • keysAdds key bindings of its own.
  • pane.focusMoves focus from one pane to the next.

Settings

Shown under the addon in Settings › Labs once it’s on.

SettingTypeDefaultDetails
Modifiermodifier Choice ctrl With ctrl, ctrl+l no longer clears the screen in your shell. One of ctrl, alt, ctrl+shift.
Programs that get the keyseditors Text nvim,vim Comma-separated foreground programs the keys pass through to. Add the Neovim snippet so they come back to Otty at the edge.

Turn it on

  1. Turn on Feature Preview in Settings › Advanced, or add feature-preview = true to your config.toml.
  2. Open Settings › Labs and switch Addons on.
  3. Switch Smart Splits on. Its settings show up right under it.

The Neovim side

Inside Neovim the keys go to Neovim. For them to come back to Otty when you reach the edge of Neovim's windows, Neovim needs this snippet:

  1. Save it as ~/.config/nvim/lua/otty.lua.
  2. Add require("otty") to your init.lua.
  3. Restart Neovim. Outside Otty the snippet only moves between Neovim windows.

It maps Ctrl+h/j/k/l. If you picked another modifier in the addon's settings, change <C- in the snippet to match.

nvim/otty.lua19 lines
-- Smart Splits for Neovim inside Otty.
-- Put this file in ~/.config/nvim/lua/ and add `require("otty")` to init.lua.
-- Ctrl+h/j/k/l moves between Neovim windows; at the edge it asks Otty to move
-- to the pane beyond. Outside Otty ($OTTY_PANE_ID unset) it only moves windows.

local directions = { h = "left", j = "down", k = "up", l = "right" }

local function move(key)
  local before = vim.api.nvim_get_current_win()
  vim.cmd("wincmd " .. key)
  if vim.api.nvim_get_current_win() == before and vim.env.OTTY_PANE_ID then
    vim.fn.jobstart({ "otty", "pane", "focus", "--direction", directions[key] }, { detach = true })
  end
end

for key in pairs(directions) do
  vim.keymap.set({ "n", "t" }, "<C-" .. key .. ">", function() move(key) end,
    { desc = "Move to the window or Otty pane " .. directions[key] })
end

Source

The whole addon is this script and its addon.toml.

main.luau19 lines
-- Smart Splits: modifier+h/j/k/l moves between panes, except while an editor
-- is in front — then the keys go to it, and its own mapping (nvim/otty.lua)
-- calls `otty pane focus --direction …` when it can't move any further.

local directions = { h = "left", j = "down", k = "up", l = "right" }

local editors = {}
for name in string.gmatch(otty.setting("editors"), "[^,%s]+") do
	table.insert(editors, name)
end

for key, direction in directions do
	otty.keys.bind({
		key = otty.setting("modifier") .. "+" .. key,
		title = "Focus Pane " .. string.upper(string.sub(direction, 1, 1)) .. string.sub(direction, 2),
		action = "pane.focus:" .. direction,
		unless_process = editors,
	})
end