Repository navigation
Description
Description
When NvimTree and windows excluded by actions.open_file.window_picker.exclude are the only windows in a tab, opening a file can replace an excluded window instead of creating a new regular window.
With the default configuration, a window containing a buftype=nofile buffer is excluded from the window picker. When that is the only non-tree window, there are no usable target windows. However, NvimTree falls back to the window from which the tree was opened and opens the file there, replacing the excluded buffer.
This appears to be a remaining edge case related to #3143/#3144: exclusions are applied while collecting usable windows, but an excluded window can still be selected as the fallback when no usable window exists.
Neovim version
NVIM v0.12.5
Build type: Release
LuaJIT 2.1.1788856981
Operating system and version
macOS 26.6.2 arm64
Windows variant
N/A
nvim-tree version
master, commit 355bcc85
Clean room replication
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",
},
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
_G.setup = function()
require("nvim-tree").setup({})
endSteps to reproduce
- Run
nvim -nu /tmp/nvt-min.luaand wait for the plugins to finish installing. - Run
:enew. - Run
:setlocal buftype=nofile. - Run
:NvimTreeOpen. - Select any file and press
<CR>.
Expected behavior
The nofile window is excluded and remains unchanged. Because no usable target window exists, NvimTree creates a new regular window and opens the selected file there.
Actual behavior
The selected file replaces the buffer in the excluded nofile window. No new regular window is created.
Activity
alex-courtis commentedon Oct 18, 2026
I'm able to replicate the behaviour:
If there is text in the scratch buffer it won't be wiped:
It may be Nvim itself that decides to wipe the empty scratch buffer.
This test indicates that I'm not understanding or replicating the issue properly.
Could you please provide another reproducer that uses, say,
filetype="yaml", removing any ambiguity around empty scratch buffers.nolleh commentedon Oct 19, 2026
Thanks. I was able to reproduce the same behaviour without using a
scratch buffer.
window_picker.excludecan be configured to exclude windows displayinga YAML buffer:
Create two non-empty files:
Steps to reproduce:
/tmp/nvt-window-picker-repro/excluded.yaml.:set filetype=yamlto ensure the buffer is excluded.:NvimTreeOpen /tmp/nvt-window-picker-repro.target.txtin NvimTree and press<CR>.Before opening
target.txt, the tab contains two windows:excluded.yamlExpected result:
excluded.yamlremains unchanged.target.txt.Actual result:
excluded.yamlis reused fortarget.txt.target.txt.This shows that the issue is not caused by Neovim wiping or reusing an
empty scratch buffer. The excluded YAML window is still selected as the
fallback target when no usable window is available.
alex-courtis commentedon Oct 19, 2026
That is expected behaviour. nvim-tree will open the file in the only available window:
excluded.yaml.window_picker.excludeis not applicable.window_picker.excludeapplies only to the case of multiple avaliable windows, see:help nvim_tree.config.actions.open_file.window_pickerDemo:
oneandtwoexcluded.yaml:e one<C-W>v:e two<C-W>v:NvimTreeOpenoneandtwobut notexcluded.yamlwindowsalex-courtis commentedon Oct 19, 2026
To achieve the functionality you are after, you will need to use a
pickerfunction that decides which window should open the file. See:help nvim_tree.config.actions.open_file.window_pickerSkeleton:
nolleh commentedon Nov 14, 2026
@alex-courtis
Thanks for the clarification. I understand now that, in the default
picker flow,
excludedoes not prevent the only non-tree window frombeing used as the fallback target.
I implemented the desired behaviour with a custom picker:
window_picker.excludevalues;A/Bpicker when there are multiple eligible windows;For anyone with a similar use case, the implementation is here:
nolleh/dotfiles@5ca9914
One small documentation suggestion: it may be helpful to explicitly mention
that
excludedoes not prevent the sole non-tree window from being used asthe fallback target, and that a custom picker is required to create a new
window in that case. I initially interpreted
excludeas a strongerguarantee that matching windows would never be used as file-open targets.
This resolves my use case, so please feel free to close the issue.
alex-courtis commentedon Nov 15, 2026
That's fantastic! Please share this on the Recipes page for others to find and use.
Is this extra text in the exclude field clear?
alex-courtis commentedon Nov 16, 2026
Thinking more on this issue and your solution, I think we can and should add it to nvim-tree. It could be a new option open_file.new_window, something like:
Are you open to creating a pull request to add this feature?
nolleh commentedon Nov 17, 2026
Thanks, I’d be happy to work on a pull request.
Before implementation, I’d like to clarify the intended semantics of
open_file.new_window. I may be interpreting the proposal differently.My custom picker treats this as the fallback behaviour for an empty set
of eligible windows:
window_picker.exclude.back to an excluded window.
A/BpickerThe existing NvimTree-only case is why this feels natural to me:
This could be represented as a fallback policy, for example:
The current remembered-window behaviour could remain the default for
backwards compatibility.
My concern with a second table of buffer option values is that the
original use case may require duplicating the same policy:
excludewould define which windows are not eligible targets, whilenew_windowwould need to repeat those values to prevent the samewindows from being used as fallback targets.
If
new_windowis also intended to apply when the user explicitlyselects a window from the multi-window picker, that seems like a
separate behaviour. Selecting a window currently means “open the file
in this window”, so changing that to “create a new window next to this
window” could be surprising.
Would a zero-candidate fallback option better match the intended
feature, or is that broader selected-window behaviour intentional?
alex-courtis commentedon Nov 17, 2026
That is sensible. open_file.new_window is too complex in implementation and from a user perspective. The multiple-one-zero fallback approach is intuitive and should cover all cases.
This approach is safe and should be reasonable to implement.
Honestly, the intended behaviour is not documented and not really known; it evolved during initial implementation many years ago and with many bug fixes.
Let's make a decision after implementation: keep the window_picker.fallback option or roll it out as an experiment which will become the new default.