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
831 stars 33 forks source link

[Bug]: not working in wezterm and git diff mode with lazy loading #178

Closed towry closed 3 months ago

towry commented 4 months ago

Similar Issues

Neovim Version

NVIM v0.10.0-dev-build-20231109-1408-gf6dcc464f Build type: Release LuaJIT 2.1.1710088188 Run "nvim -V1 -v" for more info

Multiplexer Integration

Wezterm

Multiplexer Version

wezterm 20240203-110809-5046fc22

Steps to Reproduce

Create a git conflict repo

  1. cd /tmp && mkdir testdir && cd testdir && git init
  2. nvim a.txt
  3. Please input some text in a.txt.
  4. git add a.txt && git commit -m "test"
  5. git checkout -b conflict-branch
  6. nvim a.txt
  7. Please change the content in a.txt.
  8. git add a.txt && git commit -m "make conflict"
  9. git checkout main or git checkout master
  10. nvim a.txt
  11. Please make change in a.txt again.
  12. Please commit changes.
  13. git merge conflict-branch
  14. There should be git conflict output, if not, please try by yourself.

Steps to start git mergetool

  1. cd /tmp && nvim init.lua.
  2. Please input the minimal configuration in init.lua, the contents is provided later.
  3. cd testdir && nvim .git/config
[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
  ignorecase = true
  precomposeunicode = true
[merge]
  ff = false
  tool = nvim
  conflictstyle = zdiff3
  prompt = false
[mergetool "nvim"]
  cmd = nvim -u ../init.lua -d \"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\" -c '$wincmd w' -c 'wincmd J'
  1. In testdir run git mergetool --tool nvim.
  2. Try navigate windows by using <C-l>, <C-h> etc.

NOTE:

  1. use :cq 1 in vim to abort the merge, so you can try merge again.

Expected Behavior

Navigate windows should work in wezterm and in git diff mode.

Actual Behavior

Doesn't work if:

  1. In wezterm.
  2. In git diff mode.
  3. Lazy loading by lazy.nvim.

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 = {
    {
        "mrjones2014/smart-splits.nvim",
        keys = {
            { "<C-h>", [[<cmd>lua require("smart-splits").move_cursor_left()<cr>]] },
            { "<C-j>", [[<cmd>lua require("smart-splits").move_cursor_down()<cr>]] },
            { "<C-k>", [[<cmd>lua require("smart-splits").move_cursor_up()<cr>]] },
            { "<C-l>", [[<cmd>lua require("smart-splits").move_cursor_right()<cr>]] },
        },
    },
    -- add any other pugins here
}

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

-- add anything else here
vim.opt.termguicolors = true
vim.cmd([[colorscheme blue]])

Additional Details and/or Screenshots

It works in kitty & tmux.

towry commented 4 months ago

:lua=require('smart-splits.config').multiplexer_integration output correctly: "wezterm"

towry commented 3 months ago

Just noticed the alert on your plugin's readme. The reason this happens is because the is_vim logic can not determine the current process name in git merge mode (it returns git).

Resolved by not lazy loading this plugin in vim git mode.

mrjones2014 commented 3 months ago

It should also work if you use the newest version of the Wezterm config snippet; it uses Wezterm user vars instead of inspecting the process name.