letieu / wezterm-move.nvim

Directional navigation of Neovim + Wezterm
22 stars 5 forks source link
neovim-plugin

wezterm-move.nvim

Navigate between neovim and wezterm panes.

It's just like smart-split.nvim but:

Features

Installation

{
    "letieu/wezterm-move.nvim",
    keys = { -- Lazy loading, don't need call setup() function
      { "<C-h>", function() require("wezterm-move").move "h" end },
      { "<C-j>", function() require("wezterm-move").move "j" end },
      { "<C-k>", function() require("wezterm-move").move "k" end },
      { "<C-l>", function() require("wezterm-move").move "l" end },
    },
}

Configuration Wezterm

local wezterm = require("wezterm")

local function is_vim(pane)
  local process_info = pane:get_foreground_process_info()
  local process_name = process_info and process_info.name

  return process_name == "nvim" or process_name == "vim"
end

local direction_keys = {
  Left = "h",
  Down = "j",
  Up = "k",
  Right = "l",
  -- reverse lookup
  h = "Left",
  j = "Down",
  k = "Up",
  l = "Right",
}

local function split_nav(resize_or_move, key)
  return {
    key = key,
    mods = resize_or_move == "resize" and "META" or "CTRL",
    action = wezterm.action_callback(function(win, pane)
      if is_vim(pane) then
        -- pass the keys through to vim/nvim
        win:perform_action({
          SendKey = { key = key, mods = resize_or_move == "resize" and "META" or "CTRL" },
        }, pane)
      else
        if resize_or_move == "resize" then
          win:perform_action({ AdjustPaneSize = { direction_keys[key], 3 } }, pane)
        else
          win:perform_action({ ActivatePaneDirection = direction_keys[key] }, pane)
        end
      end
    end),
  }
end

local nav_keys = {
  -- move between split panes
  split_nav("move", "h"),
  split_nav("move", "j"),
  split_nav("move", "k"),
  split_nav("move", "l"),
  -- resize panes
  split_nav("resize", "h"),
  split_nav("resize", "j"),
  split_nav("resize", "k"),
  split_nav("resize", "l"),
}

-- wezterm config
local config = {}

config.keys = nav_keys

Usage

Note: Resize only for wezterm panes, not for neovim panes. If you want to resize neovim panes, you need write your own keybindings in neovim.

Inspiration and Thanks