nvim-neo-tree / neo-tree.nvim

Neovim plugin to manage the file system and other tree like structures.
MIT License
3.8k stars 220 forks source link

BUG: #1130

Open rv-ragul opened 1 year ago

rv-ragul commented 1 year ago

Did you check docs and existing issues?

Neovim Version (nvim -v)

v0.10.0-dev-985+gae7ab9015

Operating System / Version

Debian GNU/Linux

Describe the Bug

I can't able to open terminal using :terminal command from a Neo-tree window. When I run :terminal command, neovim gives the error Can only call this function in an unmodified buffer. But I can open a terminal using :e term://bash. How to rectify this?

Screenshots, Traceback

neotree_terminal_bug.webm

Steps to Reproduce

  1. Open Neo-tree
  2. Run :terminal
  3. You can see the error.

Expected Behavior

Terminal should be opened using :terminal.

Your Configuration

-- DO NOT change the paths and don't remove the colorscheme
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", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  -- add any other plugins here
}

local neotree_config = {
  "nvim-neo-tree/neo-tree.nvim",
  dependencies = { "MunifTanjim/nui.nvim", "nvim-tree/nvim-web-devicons", "nvim-lua/plenary.nvim" },
  cmd = { "Neotree" },
  keys = {
    { "<Leader>e", "<Cmd>Neotree<CR>" }, -- change or remove this line if relevant.
  },
  opts = {
    -- Your config here
    -- ...
  },
}

table.insert(plugins, neotree_config)
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
cseickel commented 1 year ago

The sidebar has window stealing prevention. If another buffer tries to steal its window, it will try to move that buffer to another window and restore neo-tree.

This is meant as a helpful thing for when you accidentally open a file in neo-tree's window. It was never tested for terminals because that is an unusual thing to open accidentally. The usual culprits are files opened from a fuzzy finder.

The immediate answer is that you should switch to another window before opening a terminal. This should be obvious, you should not be opening anything in neo-tree's window. Just because you get away with it sometimes does not make it correct.

There's also something about the focus stealing prevention that doesn't work with terminals that should be fixed. I gotta say this is not a high priority for me but maybe someone else is interested in working on this.