GithubHelp home page GithubHelp logo

wezterm-mux.nvim's Introduction

If you are here please check out smart-splits.nvim. It has more functionalities and integrations. I put wezterm-mux.nvim together before knowing about smart-splits.nvim.

Weztem Mux + Nvim

This plugin is inspired by Vim Tmux Navigator, it allows to seemingly navigate between Wezterm panes and Nvim windows. It requires some minor configuration in the Wezterm side and setup keybindings in NeoVim.

The neovim plugin provides 4 functions that check if the movement between windows is done at an edge and a move out of neovim needs to be forward to wezterm. If the movement is performed across neovim windows these functions work as the usual <C-w>h, <C-w>j (..) combinations

Wezterm+Nvim

Installation

Packer:

use {"jonboh/wezterm-mux.nvim"}

I've only tested it with Packer, but given that this plugin is quite small and doesn't have configuration I think it should work on any other plugin manager. Let me know if it does not.

NeoVim Config

At some point in your NeoVim config you'll need to bind the keys you use to navigate between windows to the functions of this plugin

local mux = require("wezterm-mux")
vim.keymap.set("n", "<C-h>", mux.wezterm_move_left)
vim.keymap.set("n", "<C-l>", mux.wezterm_move_right)
vim.keymap.set("n", "<C-j>", mux.wezterm_move_down)
vim.keymap.set("n", "<C-k>", mux.wezterm_move_up)
vim.keymap.set("n", "<A-x>", "<C-w>q") -- some actions dont need from a specific function

Wezterm Config

You should add this configuration snippet some place in your wezterm/wezterm.lua.

local wezterm = require("wezterm")
local act = require("wezterm").action
local mux = require("wezterm").mux

local nvim = "/usr/bin/nvim" -- change this to the location of you nvim


local wez_nvim_action = function(window, pane, action_wez, forward_key_nvim)
    local current_process = mux.get_window(window:window_id()):active_pane():get_foreground_process_name()
    if current_process==nvim then
        window:perform_action(forward_key_nvim, pane)
    else
        window:perform_action(action_wez, pane)
    end
end

wezterm.on("move-left", function(window, pane)
	wez_nvim_action(window, pane,
    act.ActivatePaneDirection "Left", -- this will execute when the active pane is not a nvim instance
    act.SendKey({key="h", mods="CTRL"}) -- this key combination will be forwarded to nvim if the active pane is a nvim instance
    )
end)

wezterm.on("move-right", function(window, pane)
	wez_nvim_action(window, pane,
    act.ActivatePaneDirection "Right",
    act.SendKey({key="l", mods="CTRL"}))

end)

wezterm.on("move-down", function(window, pane)
	wez_nvim_action(window, pane,
    act.ActivatePaneDirection "Down",
    act.SendKey({key="j", mods="CTRL"}))
end)

wezterm.on("move-up", function(window, pane)
	wez_nvim_action(window, pane,
    act.ActivatePaneDirection "Up",
    act.SendKey({key="k", mods="CTRL"}))
end)

-- you can add other actions, this unifies the way in which panes and windows are closed
-- (you'll need to bind <A-x> -> <C-w>q)
wezterm.on("close-pane", function (window, pane)
   wez_nvim_action(window, pane,
    act.CloseCurrentPane {confirm=false},
    act.SendKey({key="x", mods="ALT"})
   )
end)


config = {
    -- your other configuration

    keys = {
        {
            -- your other key bindings

            -- pane move(nvim aware)
            { key = 'h',  mods = 'CTRL', action = wezterm.action({ EmitEvent = "move-left" }) },
            { key = 'l', mods = 'CTRL', action = wezterm.action({ EmitEvent = "move-right" }) },
            { key = 'j',  mods = 'CTRL', action = wezterm.action({ EmitEvent = "move-down" }) },
            { key = 'k',    mods = 'CTRL', action = wezterm.action({ EmitEvent = "move-up" }) },
            { key = 'x', mods = 'ALT', action = wezterm.action({EmitEvent="close-pane"})},
        }
    }
}

-- more config

return config

Make sure to modify the variable nvim to your nvim binary location. You can run this if you are unsure of its location:

which nvim

Additional help

You can check the relevant files in my wezterm config and neovim config from my dotfiles.

Or open an issue.

Related

  • aca/wezterm.nvim: Unfortunately this needs from an external binary to cross the nvim/wezterm boundary and it uses some deprecated neovim functionality.
  • willothy/wezterm.nvim: You could get something similar with this plugin, but it lacks the wezterm specific instructions.

wezterm-mux.nvim's People

Contributors

jonboh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.