numToStr / Navigator.nvim

:sparkles: Smoothly navigate between neovim and terminal multiplexer(s) :sparkles:
MIT License
391 stars 21 forks source link

Resizing (shrinking/growing) panes similarly to `tmux.nvim` #25

Open AndOrangutan opened 1 year ago

AndOrangutan commented 1 year ago

The only thing I have been missing since I have moved from tmux.nvim is the ability to resize panes (between Neovim and my multiplexer) seamlessly like in the gif.

https://user-images.githubusercontent.com/8199164/122721182-a61caf80-d270-11eb-9f75-0dd6343c0cb7.mp4

Thank you for this awesome plugin (and Comment.nvim), been awesome getting to use Wezterm.

Sombrer0Dev commented 11 months ago

Hi, This is how i solved this problem: WezTerm config

-- Method do send keys to nvim from Navigator.nvim readme

local w = require 'wezterm'
local a = w.action

local function is_inside_vim(pane)
        local tty = pane:get_tty_name()
        if tty == nil then return false end

        local success, stdout, stderr = w.run_child_process
            { 'sh', '-c',
                    'ps -o state= -o comm= -t' .. w.shell_quote_arg(tty) .. ' | ' ..
                    'grep -iqE \'^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?)(diff)?$\'' }

        return success
end

local function is_outside_vim(pane) return not is_inside_vim(pane) end

local function bind_if(cond, key, mods, action)
        local function callback(win, pane)
                if cond(pane) then
                        win:perform_action(action, pane)
                else
                        win:perform_action(a.SendKey({ key = key, mods = mods }), pane)
                end
        end

        return { key = key, mods = mods, action = w.action_callback(callback) }
end

-- My keys in config.keys

        -- Move Between Panes With Navigator.nvim
        bind_if(is_outside_vim, 'h', 'CTRL', a.ActivatePaneDirection('Left')),
        bind_if(is_outside_vim, 'l', 'CTRL', a.ActivatePaneDirection('Right')),
        bind_if(is_outside_vim, 'j', 'CTRL', a.ActivatePaneDirection('Down')),
        bind_if(is_outside_vim, 'k', 'CTRL', a.ActivatePaneDirection('Up')),

        -- Adjust Neovim And Wezterm Windows With Navigator.nvim
        bind_if(is_outside_vim, 'h', 'CTRL|ALT', a.AdjustPaneSize { 'Left', 2 }),
        bind_if(is_outside_vim, 'l', 'CTRL|ALT', a.AdjustPaneSize { 'Right', 2 }),
        bind_if(is_outside_vim, 'k', 'CTRL|ALT', a.AdjustPaneSize { 'Up', 2 }),
        bind_if(is_outside_vim, 'j', 'CTRL|ALT', a.AdjustPaneSize { 'Down', 2 }),

Neovim mappings config

local keymap = vim.keymap

-- Buffer Navigation
keymap.set('n', '<c-h>', '<CMD>NavigatorLeft<CR>', { desc = 'Move Split left' })
keymap.set('n', '<c-l>', '<CMD>NavigatorRight<CR>', { desc = 'Move Split right' })
keymap.set('n', '<c-j>', '<CMD>NavigatorDown<CR>', { desc = 'Move Split down' })
keymap.set('n', '<c-k>', '<CMD>NavigatorUp<CR>', { desc = 'Move Split up' })

keymap.set('n', '<a-c-h>', '<c-w>+', { desc = 'Adjust Split vertical+' })
keymap.set('n', '<a-c-l>', '<c-w>-', { desc = 'Adjust Split vertical-' })
keymap.set('n', '<a-c-k>', '<c-w>>', { desc = 'Adjust Split horizontal+' })
keymap.set('n', '<a-c-j>', '<c-w><', { desc = 'Adjust Split horizontal-' })
chuan2984 commented 6 months ago

I just tried @Sombrer0Dev's suggestion, theres an oversight in this solution and that is when you have only nvim open in a wezterm pane, the resizing does not work because nvim think it should not do anything since its the only pane but also the binded key action in wezterm does not do anything either since its considered 'inside_vim', I tried to add another condition that checks to see if vim is occupying the whole pane, but I dont really know how to do it haha.