mrjones2014 / smart-splits.nvim

🧠 Smart, seamless, directional navigation and resizing of Neovim + terminal multiplexer splits. Supports tmux, Wezterm, and Kitty. Think about splits in terms of "up/down/left/right".
MIT License
895 stars 37 forks source link

[Bug]: Neovide (or other UI?) run from WezTerm leads to error in integration logic #131

Closed mdietrich16 closed 10 months ago

mdietrich16 commented 10 months ago

Similar Issues

Neovim Version

NVIM v0.9.4 Build type: Release LuaJIT 2.1.1696795921

Multiplexer Integration

Wezterm

Multiplexer Version

wezterm 20230712-072601-f4abf8fd

Steps to Reproduce

  1. Have WezTerm and Neovim set up as described in README
  2. Open WezTerm
  3. Type neovide<CR>
  4. ...
  5. Profit!

Expected Behavior

Neovide opens and smart-splits works without WezTerm integration

Actual Behavior

Neovide opens and smart-splits works without WezTerm integration but echoes error message:

Failed to source `/home/max/.local/share/nvim/lazy/smart-splits.nvim/plugin/smart-splits.vim`

vim/_editor.lua:0: /home/max/.config/nvim/init.lua..nvim_exec2() called at /home/max/.config/nvim/init.lua:0../home/max/.local/share/nvim/lazy/smart-splits.nvim/plugin/smart-splits.vim[70]..function <SNR>9_write, line 2: Vim(let):E80: Error while writing: broken pipe

# stacktrace:
  - vim/_editor.lua:0 _in_ **cmd**
  - .config/nvim/lua/plugins/windows.lua:17 _in_ **init** -- This is where I have the smart-splits spec for lazy.nvim. This line only shows when using the init function described below!
  - .config/nvim/lua/config/plugins.lua:23
  - .config/nvim/lua/config/init.lua:7
  - .config/nvim/init.lua:5

Minimal Configuration to Reproduce

local root = vim.fn.fnamemodify('./.repro', ':p')

-- set stdpaths to use .repro
for _, name in ipairs({ 'config', 'data', 'state', 'cache' }) do
  vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
end

-- bootstrap lazy
local lazypath = root .. '/plugins/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    'git',
    'clone',
    '--filter=blob:none',
    '--single-branch',
    'https://github.com/folke/lazy.nvim.git',
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  -- do not remove the colorscheme! it makes testing nicer
  'folke/tokyonight.nvim',
  'mrjones2014/smart-splits.nvim',
  -- add any other pugins here
}

require('lazy').setup(plugins, {
  root = root .. '/plugins',
})

require('smart-splits').setup({
  -- add any options here
})

-- recommended mappings
-- resizing splits
-- these keymaps will also accept a range,
-- for example `10<A-h>` will `resize_left` by `(10 * config.default_amount)`
vim.keymap.set('n', '<A-h>', require('smart-splits').resize_left)
vim.keymap.set('n', '<A-j>', require('smart-splits').resize_down)
vim.keymap.set('n', '<A-k>', require('smart-splits').resize_up)
vim.keymap.set('n', '<A-l>', require('smart-splits').resize_right)
-- moving between splits
vim.keymap.set('n', '<C-h>', require('smart-splits').move_cursor_left)
vim.keymap.set('n', '<C-j>', require('smart-splits').move_cursor_down)
vim.keymap.set('n', '<C-k>', require('smart-splits').move_cursor_up)
vim.keymap.set('n', '<C-l>', require('smart-splits').move_cursor_right)
-- swapping buffers between windows
vim.keymap.set('n', '<leader><leader>h', require('smart-splits').swap_buf_left)
vim.keymap.set('n', '<leader><leader>j', require('smart-splits').swap_buf_down)
vim.keymap.set('n', '<leader><leader>k', require('smart-splits').swap_buf_up)
vim.keymap.set('n', '<leader><leader>l', require('smart-splits').swap_buf_right)

-- add anything else here
vim.opt.termguicolors = true
-- do not remove the colorscheme! it makes testing nicer
vim.cmd([[colorscheme tokyonight]])

Additional Details and/or Screenshots

This could be mitigated by checking for vim.g.neovide which is nil when not in Neovide and true when in Neovide, which I tried. However, this is a fairly specific addition, since other UI's exist with probably the same problem.

I would just be glad to get a pointer to where I can manually do this. I tried through the lazy.nvim opts and init function like:

    init = function()
        if vim.g.neovide then
            print("Disabled WezTerm mux integration")
            require("smart-splits.config")["multiplexer_integration"] = false
        end
    end,

But the error then just originates from that init function, which seems to mean that plugin/smart-splits.vim gets loaded when doing any require("smart-splits"). This of course makes it impossible for me to override this behaviour.

mrjones2014 commented 10 months ago

This could be mitigated by checking for vim.g.neovide which is nil when not in Neovide and true when in Neovide, which I tried. However, this is a fairly specific addition, since other UI's exist with probably the same problem.

Yeah, a more appropriate solution would probably be to just disable terminal mux integrations entirely if it's detected that you're using a GUI instead of nvim's TUI. We may be able to check that via vim.api.nvim_list_uis(). If term_name doesn't match one of ours, or if stdin_tty or stdout_tty are false, then it's probably a GUI.

mrjones2014 commented 10 months ago

Please verify that #132 resolves your issue @mdietrich16 🙏

mdietrich16 commented 10 months ago

Did a review, small changes required. If those are fixed, it seems to work with Neovide at least. Nice work!

mdietrich16 commented 10 months ago

I'll close when the PR is merged.

mrjones2014 commented 10 months ago

Thanks for the review + testing! It will auto-close the issue when I merge the PR. I'll tag a patch release after merging.

mdietrich16 commented 10 months ago

Alright, thanks for the quick and elegant fix!

lkhphuc commented 8 months ago

The latest commit https://github.com/mrjones2014/smart-splits.nvim/commit/26085a67fe4eab87d0df72402754028f54b53a3c causes the error to appear on start up again. It's not a big problem as everything still works fine. The error message only shows on startup from launching inside wezterm, not from launching Neovide from GUI.

mrjones2014 commented 8 months ago

@lkhphuc does #142 fix it for you?

lkhphuc commented 8 months ago

142 worked for me. Thanks.