Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AndOrangutan opened this issue Feb 19, 2023 · 2 comments
Open

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

AndOrangutan opened this issue Feb 19, 2023 · 2 comments

Comments

@AndOrangutan
Copy link

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.

tmux-resize.mp4

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

@Sombrer0Dev
Copy link

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-' })

@Ramilito Ramilito mentioned this issue Nov 5, 2023
5 tasks
@chuan2984
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants