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

nvim-tree.lua destroys split pattern, and now show the opened buffer #3083

Open
CoinCheung opened this issue Mar 10, 2025 · 2 comments
Open
Labels
bug Something isn't working reproduced Issue confirmed

Comments

@CoinCheung
Copy link

Description

When I open nvim and split, and then toggle with current_window=true, and then open a new file from nvim-tree. The split pattern is destroyed, and the opened new file is not on the top.

Neovim version

NVIM v0.10.4
Build type: Release
LuaJIT 2.1.1713484068
Run "nvim -V1 -v" for more info

Operating system and version

Linux WorkStation 6.11.0-19-generic #19~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Feb 17 11:51:52 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Windows variant

No response

nvim-tree version

head

Clean room replication

This is my init.lua:

-- download and install and load plugins --
-- install lazy.vim if it does not exist
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

-- install plugins
require("lazy").setup({
    {
        "nvim-tree/nvim-tree.lua",
        version = "*",
        lazy = false,
        dependencies = {
            "nvim-tree/nvim-web-devicons",
        },
    },
})

local nvim_tree_api = require("nvim-tree.api")
require('nvim-tree').setup({
    update_focused_file = {
        enable = true,
    },
    actions = {
        open_file = {
            quit_on_open = true,
            window_picker = {enable = false},
        }
    },
   git = {enable = false},
})


-----------------
-- key bindings --
-----------------
-- set <leader>
vim.g.mapleader = ","

vim.keymap.set('n', '<leader>o', ':only<cr>', opts)
vim.keymap.set('i', '<C-x>', '<esc>', opts)
vim.keymap.set('n', '<leader><cr>', ':noh<cr>', opts)
vim.keymap.set('n', 'ss', ':set spell!<cr>', opts)


-- Hint: see `:h vim.map.set()`
-- Better window navigation
vim.keymap.set('n', '<C-h>', '<C-w>h', opts)
vim.keymap.set('n', '<C-j>', '<C-w>j', opts)
vim.keymap.set('n', '<C-k>', '<C-w>k', opts)
vim.keymap.set('n', '<C-l>', '<C-w>l', opts)

-- Resize with arrows
vim.keymap.set('n', '<C-Up>', ':resize -2<CR>', opts)
vim.keymap.set('n', '<C-Down>', ':resize +2<CR>', opts)
vim.keymap.set('n', '<C-Left>', ':vertical resize -2<CR>', opts)
vim.keymap.set('n', '<C-Right>', ':vertical resize +2<CR>', opts)

-- nvim-tree shortcuts
vim.keymap.set("n", "<leader>n",
    function()
        nvim_tree_api.tree.toggle({
            path = "<args>", current_window = true,
            focus = true, find_file = false, update_root = false })
    end,
    { noremap = true })

Steps to reproduce

  1. $ nvim -u init.lua a b
  2. run :vs, here it should be like [a | b]
  3. n
  4. choose a file(such as a "c"), and press enter

Expected behavior

The split pattern should keep, and the new opened file should be in the split where nvim-tree is toggled. Here it is [c | b]

Actual behavior

The split pattern is gone, that is only a [a] is here. And the new opened file of "c" is not on top of the shown buffers.

@CoinCheung CoinCheung added the bug Something isn't working label Mar 10, 2025
@alex-courtis
Copy link
Member

Next time please follow the instructions when creating the replicator:

Minimal(!) configuration necessary to reproduce the issue. If not provided it is very unlikely that the nvim-tree team will be able to address your issue. See wiki: Clean Room Replication for instructions and paste the contents of your /tmp/nvt-min.lua here. Please do NOT post a configuration that uses other plugin managers such as lazy, see wiki: Lazy Loading

On simplifying the toggle I am able to reproduce via:

nvim -nu nvt-min.lua a b
:vs
:n
,n
select c
<only window with a is open>
vim.keymap.set("n", "<leader>n",
  function()
    nvim_tree_api.tree.toggle(
      {
        current_window = true,
      }
    )
  end,
  { noremap = true }
)

Please note from #3080 that path = "<args>", is incorrect and may yield unexpected results.

@alex-courtis alex-courtis added the reproduced Issue confirmed label Mar 16, 2025
@alex-courtis
Copy link
Member

alex-courtis commented Mar 16, 2025

Minimal reproducer, both quit-on-open and window-picker-disabled are required. Update-focused-file irrelevant.

Any thoughts on this one @GCrispino ? We definitely tested the _no_window_picker APIs #3054

echo a > a
echo b > b
echo c > c
nvim -nu nvt-min.lua a b
:vs
:n
<space>a
<CR> on c
buffer a is shown, not c
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvt-min/site]])
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
  require("packer").startup({
    {
      "wbthomason/packer.nvim",
      "nvim-tree/nvim-tree.lua",
      "nvim-tree/nvim-web-devicons",
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. "/plugin/packer_compiled.lua",
      display = { non_interactive = true },
    },
  })
end
if vim.fn.isdirectory(install_path) == 0 then
  print("Installing nvim-tree and dependencies.")
  vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path })
end
load_plugins()
require("packer").sync()
vim.cmd([[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]])
vim.opt.termguicolors = true
vim.opt.cursorline = true

local api = require("nvim-tree.api")

vim.keymap.set("n", "<space>a", function()
  api.tree.toggle({ current_window = true })
end, { noremap = true })

-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
  require("nvim-tree").setup({
    actions = {
      open_file = {
        quit_on_open = true,
        window_picker = {
          enable = false
        },
      }
    },
  })
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reproduced Issue confirmed
Projects
None yet
Development

No branches or pull requests

2 participants